重大变化:默认导出
默认情况下,Node.js 允许使用语法 import sass from 'sass'
从 ECMAScript 模块加载 CommonJS 模块。现在已弃用;ESM 用户应使用 import * as sass from 'sass'
。
从历史上看,Dart Sass 仅作为 CommonJS 模块提供。这意味着任何在使用 Node.js 原生 ECMAScript 模块支持的项目中使用它的人都能够加载它,就像它提供了 默认导出 一样:
¥Historically, Dart Sass was only available as a CommonJS module. This meant that anyone using it from a project that used Node.js’s native ECMAScript module support was able to load it as though it provided a default export:
import sass from 'sass'; // Don't do this anymore
这并不是 Sass 团队的初衷,而且它与包中提供的类型声明不匹配,但它确实有效。我们决定在 Dart Sass 2.0.0 中删除此支持,并要求 ECMAScript 模块用户仅使用包的命名导出:
¥This was never intended by the Sass team, and it didn’t match the type declarations provided with the package, but it did work. We have decided to remove this support in Dart Sass 2.0.0 and require that ECMAScript module users only use the package’s named exports:
import * as sass from 'sass'; // Do this
过渡期过渡期 permalink
¥Transition Period
- Dart Sass
- since 1.54.0
- LibSass
- ✗
- Ruby Sass
- ✗
直到 Dart Sass 2.0.0,我们将继续支持用户加载 Sass 的默认导出。第一次访问默认导出上的任何属性时,它将向 console.error()
发出弃用警告。要避免此错误,请改用 import * as sass from 'sass'
。
¥Until Dart Sass 2.0.0, we will continue to support users loading Sass’s default
export. The first time any properties on the default export are accessed, it
will emit a deprecation warning to console.error()
. To avoid this error, use
import * as sass from 'sass'
instead.