简体   繁体   English

是使用 Live Sass 编译器(VS 代码扩展)还是通过 npm 安装和运行 Sass 更好? (+ 提示如何从 node-sass 更改为 dart-sass)

[英]Is it better to use the Live Sass Compiler (VS Code extension) or to install and run Sass via npm? (+ tips how to change from node-sass to dart-sass)

I am doing an online course on Advanced CSS and Sass and found out that the way it is shown in the course is a bit outdated.我正在上高级 CSS 和 Sass 的在线课程,发现课程中显示的方式有点过时了。

The course uses node-sass in the dependencies, which is deprecated.该课程在依赖项中使用 node-sass,已弃用。 A direct alternative to this would be to use Dart-sass (I will write my steps to do so in the end, maybe someone will benefit from this:))一个直接的替代方法是使用 Dart-sass (我将在最后编写我的步骤,也许有人会从中受益:))

Another alternative is to use the VS Code Extension "Live Sass Compiler".另一种选择是使用 VS 代码扩展“Live Sass 编译器”。 It seems that this option is quite well accepted.似乎这个选项被很好地接受了。

However, I wonder what benefits and differences these options have.但是,我想知道这些选项有什么好处和区别。 Eg I had some troubles with the extension yesterday and then used the dart sass as a dependency and solved my problem this way.例如,我昨天在扩展时遇到了一些麻烦,然后使用 dart sass 作为依赖项,并以这种方式解决了我的问题。 Maybe this was due to something wrong in my code, but still, it left me with this question and I think others might have the same in the future.也许这是由于我的代码中有问题,但它仍然给我留下了这个问题,我认为其他人将来可能会有同样的问题。


PS: It is my first question here, don't roast me if I did something wrong:D PS:这是我的第一个问题,如果我做错了不要烤我:D

For those interested in how to change the code from node-sass to dart-sass here are the steps (at least for me these were the steps in the course I did):对于那些对如何将代码从 node-sass 更改为 dart-sass 感兴趣的人,这里是步骤(至少对我来说,这些是我所做的课程中的步骤):

  1. Install dart sass using the command line: npm i -D sass使用命令行安装 dart sass: npm i -D sass
  2. Change your scripts where it says node-sass to just be sass (in package.json)将您的脚本更改为node-sasssass (在 package.json 中)
  3. Change the -w in your watch:sass script to --watch (in package.json)将手表中的-w watch:sass脚本更改为--watch (在 package.json 中)
  4. You can also do npm uninstall node-sass to get rid of it你也可以做npm uninstall node-sass来摆脱它

I do not know what exact tutorial you are looking at.我不知道你在看什么确切的教程。 Also, I am not so experienced at the front-end, but in my opinion, using Sass as a css-preprocessor isn't the best option on production for now.此外,我在前端的经验并不丰富,但在我看来,使用 Sass 作为 css 预处理器目前并不是生产中的最佳选择。

But, since you are asking how to implement sass , I'll describe a procedure, like you are using React with npx create-react-app .但是,既然您要问如何实现sass ,我将描述一个过程,就像您将 React 与npx create-react-app一起使用。

First, you were right, about using dart-sass over sass .首先,你是对的,关于在sass上使用dart-sass This command should help you with that: npm install --save-dev sass .此命令应该可以帮助您: npm install --save-dev sass According to the question, seems you already tried that.根据问题,您似乎已经尝试过了。

After that, add new script to your scripts in your package.json file: "sass": "sass src/Sass:src/Css --watch --no-source-map" and you are done.之后,在package.json文件中添加新scripts"sass": "sass src/Sass:src/Css --watch --no-source-map"就完成了。

In my own opinion, I prefer to implement it via npm instead of VSC plugin.在我自己看来,我更喜欢通过npm而不是 VSC 插件来实现它。 It will more stable after all.毕竟会更稳定。 But if you are using it, for test/study purposes, I think, you could try both.但是,如果您出于测试/研究目的而使用它,我认为您可以同时尝试。

If you want to use the most actual version Dart SASS with 'Live Sass Compiler' you need to take care about the version.如果您想使用最实际的版本 Dart SASS 和“Live Sass Compiler”,您需要注意版本。 The most popular version is not supported for years so it does not support Dart Sass.最受欢迎的版本多年来不受支持,因此它不支持 Dart Sass。

But there is a fork which is supported and as fork you can use same settings.但是有一个支持的叉子,作为叉子,您可以使用相同的设置。

To your Question about NPM and Live Sass Compiler: both are Javascript Version off Sass.关于 NPM 和 Live Sass 编译器的问题:两者都是 Javascript 版本关闭 Z8B8D7133FC325F758DZF02。 As Javascript versions they are not as fast as if you install SASS direct on your System.作为 Javascript 版本,它们不如直接在系统上安装 SASS 快。 The difference between Javascript vesion itself its not as big. Javascript vesion 之间的差异本身并没有那么大。 So I think the best choice between NPM and Live Sass compiler is to use Live Sass Compiler (the forked version.) as it is integrated to the editor and easier to use direct from there.所以我认为 NPM 和 Live Sass 编译器之间的最佳选择是使用 Live Sass 编译器(分叉版本),因为它已集成到编辑器中,并且更易于直接使用。

If you need a faster solution you really should install the original version.如果您需要更快的解决方案,您真的应该安装原始版本。 That is not as difficult as it sounds.这并不像听起来那么困难。 And there is a VS Code Extension as well wich make it possible to use that original installed version easy direct up from VS Code.并且还有一个 VS Code 扩展,可以直接从 VS Code 轻松使用原始安装的版本。

Detailed Information:详细资料:

Install SASS direct on your system:直接在您的系统上安装 SASS:
https://sass-lang.com/install https://sass-lang.com/install

Information to the named VS Code extension:命名 VS Code 扩展的信息:
https://stackoverflow.com/a/66207572/9268485 https://stackoverflow.com/a/66207572/9268485

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM