Vue CLI CSS 预处理器选项:dart-sass VS node-sass? [英] Vue CLI CSS pre-processor option: dart-sass VS node-sass?
问题描述
使用 CLI (v3.7.0) 创建新项目时,可以选择 dart-sass
或 node-sass
编译器.
这些如何相互比较,比在
- 在这种特殊情况下,两秒不是什么大问题;但考虑到 Dart-Sass(JS) 比 Dart-Sass(Dart VM) 慢 9 倍,比 node-sass 慢 3 倍.
- 我有一个包含 +20 个主题的项目,使用 node-sass 花了 30 秒,但是我尝试使用 Dart-Sass(JS),却花了一个世纪!
- 虽然 Dart-Sass(Dart VM) 是最快的,但安装或集成它有点棘手.
- Node-Sass 被认为已弃用.
我 博客在这里,你可以在这里阅读更多.
When creating a new project with CLI (v3.7.0), there is an option to choose between dart-sass
or node-sass
compiler.
How do these compare to each other, to be more specific than declared in Vue docs?
A Tip on Sass Performance
Note that when using Dart Sass, synchronous compilation is twice as fast as asynchronous compilation by default, due to the overhead of asynchronous callbacks. To avoid this overhead, you can use the fibers package to call asynchronous importers from the synchronous code path. To enable this, simply install fibers as a project dependency:
npm install -D fibers
Please also be aware, as it's a native module, there may be compatibility issues vary on the OS and build environment. In that case, please run
npm uninstall -D fibers
to fix the problem.
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): (Use arrow keys)
❯ Sass/SCSS (with dart-sass)
Sass/SCSS (with node-sass)
Less
Stylus
EDIT 2020/01: Vue CLI 4.2.2 create new project is still suggesting dart-sass
as the first option before node-sass
. Yet it has been established here that node-sass
is the more performant choice, and almost nobody uses dart-sass (ccleve's comment).
EDIT 2020/09: As Ali Bahrami updated his extensive answer, dart-sass
is the preferred choice as node-sass
is being marked as deprecated.
Too bad dart-sass
in it's a JS-compiled version has poor performance. However, it's developers are well aware of this, and are working towards greater performance as stated in this issue.
Update 09/17/2020:
As this answer gets up-votes every day, I thought maybe it is worth diving deeper into this topic.
Considering sass-lang website:
Dart Sass is the primary implementation of Sass, which means it gets new features before any other implementation. It's fast, easy to install, and it compiles to pure JavaScript which makes it easy to integrate into modern web development workflows.
Dart-Sass is fast, but not the JS compiled version. Practically when we say Dart-Sass there are two options:
- Dart-Sass on Dart-VM
- Dart-Sass on NPM which is pure JS compiled version
I compiled Bootstrap 4 Sass file to CSS with Node-Sass, Dart-Sass and Dart-Sass(JS) and you can see the following result:
- In this particular case, two seconds is not a big deal; but consider Dart-Sass(JS) is nine times slower than Dart-Sass(Dart VM) and three times slower than node-sass.
- I had a project with +20 themes, it took 30 seconds with node-sass, but I tried to use Dart-Sass(JS), and it took a century!
- Although Dart-Sass(Dart VM) is the fastest but installing or integrating it is a bit tricky.
- And Node-Sass is considered deprecated.
I blogged about it here, you can read more about it here.
这篇关于Vue CLI CSS 预处理器选项:dart-sass VS node-sass?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!