如何在 Linux / macOS 上使用 Sass 和 NetBeans



我曾经能够将 Sass 与 NetBeans 8 一起使用,如 如何将 SASS 与 NetBeans 8.0.1 一起使用的顶部答案中所述

现在,对于当前版本的 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".

此错误也包含在 Netbeans 8.2 中使用 Windows 的 Sass 输出错误中。

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

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 工作有任何想法吗?

问题是--cache-location不再受支持,应该删除。所有原始参数都由"$@"使用。要删除前两个参数,您应该能够使用"${@:3}"(请参阅处理除第一个参数之外的所有参数(在 bash 脚本中((,但不知何故,这导致了我的"错误替换"错误。所以我选择使用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 (Home Brew(

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

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

macOS (node.js(

使用 node.js 时,您会遇到"env:node:没有这样的文件或目录"问题。

要解决我创建的解决方法(确保使其可执行(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

我的回答主要基于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开发人员知道这个错误(请参阅:找不到名为"cache-location"的选项(,但我无法实现这一点,因为在我的Xubuntu 18下,Netbeans是一个"快照",因此它的netbeans.conf文件是只读的。 但是,如果您可以修改该文件,则可能是一个更干净的解决方案。