从node-sass迁移到dart-sass

库名 库状态 描述
node-sass 废弃 sass预处理器的编译器,是调用libsass的node中间件。官方说明:Node-sass is a library that provides binding for Node.js to LibSass, the C version of the popular stylesheet preprocessor, Sass.
Dart-sass 维护中 sass的dart实现。官方说明:A Dart implementation of Sass.
Sass 维护中 sass预处理器的编译器,node实现。

以上三个库均为官方提供,上述表格为截止 2020-12-29 的状态。

为什么迁移?

  • 官方宣布废弃:目前node-sass已经由于不支持新版本sass的一些特性等原因废弃(编译器API支持程度一定程度上抑制了sass的发展),官方推荐迁移到dart-sass。

  • node-sass的安装条件复杂:因为是调用c/c++进行的编译,所以在npm install的postinstall阶段需要根据不同的CPU和系统环境进行该环境下的编译可执行文件的获取。

    • node版本有预依赖:node-sass部分代码如下

      variant = getPlatformVariant();
      if (variant) {
        platform += '_' + variant;
      }
      binaryName = [
        platform, '-',
        process.arch, '-',
        process.versions.modules
      ].join('');
      
      node版本对应列表.png
  • gcc版本可能会有依赖:二进制文件执行需要本地的gcc(此处会要求依赖的gcc版本)编译。

如何迁移?

How do I migrate?

If you’re a user of Node Sass, migrating to Dart Sass is straightforward: just replace node-sass in your package.json file with sass. Both packages expose the same JavaScript API.

If you’re using the SassC command-line interface, you can switch to Dart Sass’s CLI. Note that this doesn’t have exactly the same interface as SassC, so you may need to change a few flags.

If you’re using LibSass through a wrapper library in another language, you can either switch to the Dart Sass CLI or ask the maintainer of the LibSass wrapper to convert it to a host for the Sass embedded protocol. The embedded protocol allows any language to provide a native API that calls out to Dart Sass.

Please note that because activity on LibSass has been low for several years, it has a number of outstanding bugs and behavioral variations from the Sass spec. You may need to make minor updates to stylesheets to make them compatible with Dart Sass. See this list of major compatibility issues for reference.

迁移注意事项:

  1. Deep-selectors检查: /deep/在dart-sass中不受支持,使用良好的选择器结构避免或使用相关领域loader独有的语法,如:https://vue-loader.vuejs.org/guide/scoped-css.html#deep-selectors。

你可能感兴趣的:(从node-sass迁移到dart-sass)