【问题标题】:How to use Sass with NetBeans on Linux / macOS如何在 Linux / macOS 上将 Sass 与 NetBeans 一起使用
【发布时间】:2019-03-16 09:21:52
【问题描述】:

我曾经能够按照How to use SASS with Netbeans 8.0.1 上的最佳答案中的描述在 NetBeans 8 中安装和使用 Sass

现在,使用当前版本的 Sass (1.14.1),安装有所不同。基本上只需下载和解压缩。完成后,我已将 NetBeans 指向正确的位置。但是当前版本的 Sass 无法从 NetBeans 正确运行:

"/opt/dart-sass/sass" "--cache-location" 
"/home/jasper/.cache/netbeans/8.2/sass-compiler"
"path_to_my.scss" "path_to_my.css"
Could not find an option named "cache-location".

Sass output error in Netbeans 8.2 在他们使用 Windows 的地方也涵盖了此错误。

我尝试在sass文件的这一行添加缓存位置参数(类似于Windows的解决方案):

exec "$path/src/dart" --no-preview-dart-2 "-Dversion=1.14.1" "$path/src/sass.dart.snapshot" "$@"

但我无法让它工作(同样的错误不断出现)。

有人知道如何让 Sass 1.14.1 在 Linux (Ubuntu) 上从 NetBeans 8.2 运行吗?

【问题讨论】:

    标签: linux ubuntu netbeans sass


    【解决方案1】:

    问题是 --cache-location 不再受支持,应该被删除。 "$@" 使用所有原始参数。要删除前两个参数,您应该能够使用"${@:3}"(请参阅Process all arguments except the first one (in a bash script)),但不知何故,这导致了我的“错误替换”错误。所以我选择使用shift 2 来删除它们:

    #!/bin/sh
    # Copyright 2016 Google Inc. Use of this source code is governed by an MIT-style
    # license that can be found in the LICENSE file or at
    # https://opensource.org/licenses/MIT.
    
    # This script drives the standalone Sass package, which bundles together a Dart
    # executable and a snapshot of Sass. It can be created with `pub run grinder
    # package`.
    
    follow_links() {
      file="$1"
      while [ -h "$file" ]; do
        # On Mac OS, readlink -f doesn't work.
        file="$(readlink "$file")"
      done
      echo "$file"
    }
    
    # Unlike $0, $BASH_SOURCE points to the absolute path of this file.
    path=`dirname "$(follow_links "$0")"`
    shift 2
    exec "$path/src/dart" --no-preview-dart-2 "-Dversion=1.14.1" "$path/src/sass.dart.snapshot" "${@}"
    

    确保保留原始文件并创建一个仅用于 NetBeans 的副本并在此处进行更改。

    macOS(自制)

    如果您正在寻找 Dart Sass 安装位置(使用 Home Brew 安装后),它位于此处:

    /usr/local/Cellar/sass/{version}/bin
    

    macOS (node.js)

    使用 node.js 时,会遇到"env: node: No such file or directory" 问题。

    解决我创建的问题(确保将其设为可执行 (chmod a+x)):

    /usr/local/lib/node_modules/sass/sass_nb.sh
    

    并添加:

    #!/bin/zsh
    
    export PATH="$PATH:"/usr/local/bin/
    shift 3
    sass ${@}
    

    NetBeans 11+

    在 NetBeans 11 和 12 上,我必须使用 shift 3 而不是 shift 2

    【讨论】:

    • 遇到同样的问题。接受的答案中需要编辑的文件的名称是什么?
    • @phaworth 查看我的详细答案。
    【解决方案2】:

    我的回答主要基于 Jasper de Vries'one:

    似乎 Netbeans 只是简单地添加了一些 sass 编译器不再支持的附加参数。

    在我的例子中,Netbeans 发出的完整命令是:

    "/home/alex/tools/dart-sass/sass" "--cache-location" "/home/alex/snap/netbeans/common/cache/12.0/sass-compiler" "--debug-info " "/home/alex/projects/alexgheorghiu.com/web/aaa.scss" "/home/alex/projects/alexgheorghiu.com/web/aaa.css"

    所以前3个参数

    "--cache-location" "/home/alex/snap/netbeans/common/cache/12.0/sass-compiler" "--debug-info"

    必须“删除”或忽略。

    因此您需要更改 sass 文件或复制它(最安全的方式) 并添加

    shift 3
    

    说明。

    因此,如果您从原始版本开始,例如:

    #!/bin/sh
    
    # This script drives the standalone dart-sass package, which bundles together a
    # Dart executable and a snapshot of dart-sass.
    
    follow_links() {
      file="$1"
      while [ -h "$file" ]; do
        # On Mac OS, readlink -f doesn't work.
        file="$(readlink "$file")"
      done
      echo "$file"
    }
    
    # Unlike $0, $BASH_SOURCE points to the absolute path of this file.
    path=`dirname "$(follow_links "$0")"`
    exec "$path/src/dart" "$path/src/sass.snapshot" "$@"
    

    你需要得到类似的结果:

    #!/bin/sh
    
    # This script drives the standalone dart-sass package, which bundles together a
    # Dart executable and a snapshot of dart-sass.
    
    follow_links() {
      file="$1"
      while [ -h "$file" ]; do
        # On Mac OS, readlink -f doesn't work.
        file="$(readlink "$file")"
      done
      echo "$file"
    }
    
    # Unlike $0, $BASH_SOURCE points to the absolute path of this file.
    path=`dirname "$(follow_links "$0")"`
    shift 3
    exec "$path/src/dart" "$path/src/sass.snapshot" "$@"
    

    一个有趣的方面是 Netbeans 开发人员知道这个错误(请参阅:Could not find an option named "cache-location")但我无法实现这一点,因为在我的 Xubuntu 18 下,Netbeans 是一个“快照”,因此它的 netbeans.conf 文件是只读。 但如果您可以修改该文件,它可能是一个更清洁的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 2020-08-24
      • 1970-01-01
      • 2016-12-24
      • 2012-10-15
      • 1970-01-01
      • 2010-12-25
      相关资源
      最近更新 更多