@bigcommerce/node-sass

中文文档
10.0.2发布于 2025/11/04MITCommonJS近 30 天下载 6173

环绕自来水

中文使用文档
文档目录51 节
  1. 节点版本支持策略
  2. 安装
  3. 从中国镜像安装
  4. 使用量
  5. 选项
  6. 文件
  7. 数据
  8. 进口商(xq v 2. 0.0) - 实验
  9. 函数 (qqv3. 0.0) - 实验
  10. 包括路径
  11. 缩进语法
  12. 缩进Type( QQ v3. 0.0)
  13. 缩进Width( QQ v3. 0.0)
  14. 线条feed (>= v3. 0.0)
  15. 删除 SourceMapUrl
  16. 输出文件
  17. 输出样式
  18. 精确度
  19. 来源注释
  20. 来源映射
  21. 源代码
  22. 源代码
  23. 来源地图
  24. render 回调( QQ v3. 0.0)
  25. 错误对象
  26. 结果对象
  27. 实例
  28. 特殊行为
  29. 版本信息 (QQ v 2. 0
  30. 一体化
  31. 括号扩展名
  32. 布鲁奇插件
  33. 连接/ 执行中间软件
  34. DocPad 插件
  35. Duo.js 扩展名
  36. Grunt 扩展名
  37. Gulp 扩展
  38. 枪声
  39. 金属匠插件
  40. 气象插件
  41. 米莫萨模块
  42. 示例应用
  43. 重建二进制
  44. 命令行接口
  45. 使用量
  46. 二进制配置参数
  47. 安装后构建
  48. 维护者
  49. 贡献者
  50. 关于补丁/ pulll 请求的说明
  51. 版权

节点ass

这是一个被维护的节点-sass分叉,最初由节点-sass团队所创建.

节点版本支持策略

  1. 支持的Node.js版本因发布而异,请参考 页 次。 。 。 .
  2. 命中末端的节点版本 https://github.com/nodejs/放行 (英语),将在每次节点ass放出(主要,次要)时从支持中去掉.
  3. 我们将停止为无支持的释放建立二进制,在依赖兼容性方面测试断裂,但我们不会阻挡那些想要支持自己的人的安装.
  4. 新的节点发布需要小的内部修改,同时需要CI提供者的支持(AppVeyor, GitHub Actions). 我们将开放一个单一问题,供有关各方同意并解决其他问题.

以下是最小和最大支持的节点ass版本的快速指南:

节点JS支持的节点ass版本节点模块
节点 209.0+ (中文(简体) )115 (韩语)
节点198.0+ (中文(简体) )页:1
节点 188.0+ (中文(简体) )108国
节点177.0+, < 8.0] (中文(简体) )102 (韩语)
节点 166.0+ (中文(简体) )93国道
节点155.0+,小于7.088国道
节点144.14+, < 9.0] (中文(简体) )83个
节点134.13+, < 5.0页:1
节点 124.12+,小于8.0个72国
节点 114.10+, < 5.067国道
节点 104.9+,小于 6.0 键64国道
节点 84.5.3 +, < 5.0页:1
节点 < 8< 5.0 时< 57 个
Sass logo

Alpine Linux macOS Windows x64 Linting Windows x86 Coverage Status

节点ass是一个为节点提供约束的库.js to 属性, C 版本的流行样式表预处理器, Sass.

它允许您以不可思议的速度在本地编译.css文件到cs,并通过连接中件自动编译.

在npm上发现: https://www.npmjs.com/package/node-sass (中文(简体) )

在推特上跟随@nodesass https://twitter.com/nodesass 页面存档备份,存于互联网档案馆

安装

npm install node-sass

一些用户报告了在Ubuntu上安装的问题,原因是 node 正在注册到另一个软件包. 跟随官方的节点JS文件 以安装节点JS #!/usr/bin/env node 正确的解决.

在 Windows 机器上编译需要 节点- 吉普先决条件。 。 。 .

您是否看到以下错误 ? 看看我们 解决问题指南∗∗ 载于A/AC.96/11号文件

SyntaxError: Use of const in strict mode.

安装有问题吗? 看看我们 解决问题指南。 。 。 .

从中国镜像安装

npm install -g mirror-config-china --registry=https://registry.npmmirror.com
npm install node-sass

使用量

var sass = require('node-sass');
sass.render({
  file: scss_filename,
  [, options..]
}, function(err, result) { /*...*/ });
// OR
var result = sass.renderSync({
  data: scss_content
  [, options..]
});

选项

文件

  • 类型 : String
  • 默认 : null

特别数字 : file 或者说 data 必须指定

文件路径 属性 要编译.

数据

  • 类型 : String
  • 默认 : null

特别数字 : file 或者说 data 必须指定

要传递的字符串 属性 要编译。 建议您使用 includePaths 与此相关联,以便 属性 使用时可以找到文件 @import 指令.

进口商(xq v 2. 0.0) - 实验

这是LibSass的实验性特征. 谨慎使用.

  • 类型 : Function | Function[] 签名 function(url, prev, done)
  • 默认 : undefined

函数参数和信息:

  • url (String) - 导入路径 作为,哪个 属性 遇到
  • prev (String) - 先前解决的路径
  • done (Function) - 调用函数以引用 aync 补全,取一个包含
    • file (String) - 用于 属性 用于 或
    • contents (String) - 所导入的内容(例如从内存或文件系统读取)

何时处理 属性 遇到 @import 指令。 自定义进口商允许扩展 属性 以同步和同步方式运行的引擎。 在这两种情况下,目标是 return 或打电话 done() 以对象字形表示。 根据物体字面值的不同,将发生两件事之一.

返回或呼叫时 done() 与 { file: "String" },则将假设为 @import。建议注意: prev 在可能需要相对路径解析的情况下.

返回或呼叫时 done() 与 { contents: "String" },字符串值将用作文件通过外部来源读取.

从 v3. 0.0 开始 :

  • this 是指直接运行时的背景范围 sass.render 或者说 sass.renderSync

  • 导入者可以返回错误, LibSass 将发出错误作为回应 。 例如:

    done(new Error('doesn\'t exist!'));
    // or return synchronously
    return new Error('nothing to do here');
    
  • 导入器可以是一系列函数,LibSass会按其发生于数组的顺序调用. 这有助于用户指定特定类型路径的特殊导入者(文件系统,http). 如果进口商不想处理某一特定路径,则应返回 null。见 职能科 更多关于Sass类型的细节.

函数 (qqv3. 0.0) - 实验

这是LibSass的实验性特征. 谨慎使用.

functions 是一个 Object 包含一组自定义函数,这些函数可由正在编译的 sass 文件引用。 它们可能取出零或更多输入参数,必须同步返回一个值(return ...;)或同步(done();) (中文(简体) ). 这些参数将是载于《建筑手册》的施工者之一的例子 require('node-sass').types 散货 返回值也必须是其中之一。 见下文现有类型清单:

类型

  • getValue()编号 : setValue(value) : 获得/设置数字的数字部分
  • getUnit() 编号 : setUnit(unit) : 获得/ 设置数字的单位部分

类型. String(值)

  • getValue() 编号 : setValue(value) : 获取/ 设置被绑定的字符串

类型。 颜色(r, g, b [, a = 1.0])或类型. 颜色( argb)

  • getR() 编号 : setR(value) : 红色组件(整数来自 0 改为 255(中文(简体) )
  • getG() 编号 : setG(value) : 绿色组件(整数来自 0 改为 255(中文(简体) )
  • getB() 编号 : setB(value) : 蓝色组件(整数来自 0 改为 255(中文(简体) )
  • getA() 编号 : setA(value) : alpha 组件(数字来自 0 改为 1.0(中文(简体) )

示例

var Color = require('node-sass').types.Color,
  c1 = new Color(255, 0, 0),
  c2 = new Color(0xff0088cc);

类型。Boolean(值)

  • getValue() : 获取附件布尔
  • types.Boolean.TRUE : Singleton 实例 types.Boolean 持有"真理"
  • types.Boolean.FALSE : Singleton 实例 types.Boolean 写着"假"

类型.List(长 [,逗号分隔符=正 )

  • getValue(index) 编号 : setValue(index, value) 数字 : value 本身必须是建造者之一的例子 sass.types。 。 。 .
  • getSeparator() 编号 : setSeparator(isComma) : 是否使用逗号作为分隔符
  • getLength()

类型

  • getKey(index) 编号 : setKey(index, value)
  • getValue(index) 编号 : setValue(index, value)
  • getLength()

类型

  • types.Null.NULL : Singleton 实例 types.Null。 。 。 .

示例

sass.renderSync({
  data: '#{headings(2,5)} { color: #08c; }',
  functions: {
    'headings($from: 0, $to: 6)': function(from, to) {
      var i, f = from.getValue(), t = to.getValue(),
          list = new sass.types.List(t - f + 1);

      for (i = f; i <= t; i++) {
        list.setValue(i - f, new sass.types.String('h' + i));
      }

      return list;
    }
  }
});

包括路径

  • 类型 : Array<String>
  • 默认 : []

一系列路径 属性 可以寻找 试图解决你的 @import 声明。 使用时 data,建议您使用这个.

缩进语法

  • 类型 : Boolean
  • 默认 : false

true 启用值 Sass 缩进语法 用于解析数据字符串或文件.

说明: 节点-sass/libsass会编译一个混合库来编译 scs和缩进的语法(.sass)文件,并设置默认设置(false),只要.sass和.scs扩展在文件名中使用.

缩进Type( QQ v3. 0.0)

  • 类型 : String
  • 默认 : space

用于确定是使用空格还是制表符来缩进 .

缩进Width( QQ v3. 0.0)

  • 类型 : Number
  • 默认 : 2
  • 最大数 : 10

用于确定用于缩进的空格或标签数量.

线条feed (>= v3. 0.0)

  • 类型 : String
  • 默认 : lf

用于决定是否使用 cr, (中文(简体) ), crlf, (中文(简体) ), lf 或者说 lfcr 换行序列.

删除 SourceMapUrl

  • 类型 : Boolean
  • 默认 : false

特殊 : 当使用时,您还应当指定 outFile 避免出乎意料的行为.

true 值会禁用输出文件中包含源地图信息.

输出文件

  • 类型 : String | null
  • 默认 : null

特殊 : 需要时间 sourceMap 是真实值

指定输出文件的预定位置。 强烈地建议在输出出源地图时,使其能正确回溯到预定文件.

请注意 启用此选项 没有 在磁盘上为您写入文件,仅用于内部参考目的(例如生成地图).

如何在磁盘上写入的示例

sass.render({
    ...
    outFile: yourPathTotheFile,
  }, function(error, result) { // node-style callback from v3.0.0 onwards
    if(!error){
      // No errors during the compilation, write this result on the disk
      fs.writeFile(yourPathTotheFile, result.css, function(err){
        if(!err){
          //file written on disk
        }
      });
    }
  });
});

输出样式

  • 类型 : String
  • 默认 : nested
  • 数值 : nested, (中文(简体) ), expanded, (中文(简体) ), compact, (中文(简体) ), compressed

确定 CSS 最终样式的输出格式.

精确度

  • 类型 : Integer
  • 默认 : 5

用于确定小数点后允许多少位数字 。 例如,如果你有小数 1.23456789 准确性 5,结果将是 1.23457 在最终的CSS.

来源注释

  • 类型 : Boolean
  • 默认 : false

true 启用指定向编译的 CSS 中释放的选择器的行号和文件作为注释 。 可用于调试,特别是在使用进口和混合时.

来源映射

  • 类型 : Boolean | String | undefined
  • 默认 : undefined

启用源映射生成 render 财务报告和审定财务报表 renderSync。 。 。 .

何时 sourceMap === true,该值为 outFile 用作带有后缀的源图的目标输出位置 .map 附录。 若无 outFile 已经设定, sourceMap 参数被忽略.

何时 typeof sourceMap === "string",该值为 sourceMap 将用作文件的写入位置.

源代码

  • 类型 : Boolean
  • 默认 : false

true 包括 contents 在源地图信息中

源代码

  • 类型 : Boolean
  • 默认 : false

true 将源地图嵌入为数据 URI

来源地图

  • 类型 : String
  • 默认 : undefined

该值将作为 sourceRoot 在源地图信息中

render 回调( QQ v3. 0.0)

节点- ass 支持标准节点样式的同步调用, 并签名 function(err, result)在错误条件下 error 参数中含有错误对象。 在成功的条件下 result 对象中包含一个描述渲染调用结果的对象.

错误对象

  • message (String) - 错误消息.
  • line (数目) - 出错的行号.
  • column (数目) - 出错的列数.
  • status (数量) - 状态代码.
  • file (String) - 错误的文件名 。 以防万一 file 未设置选项(赞成) data),这将反映数值 stdin。 。 。 .

结果对象

  • css (Buffer) - 编译的CSS. 把这个写到档案里 或按需要发报.
  • map (Buffer) - 源地图
  • stats (Object) - 包含编译信息的对象. 它包含以下密钥:
    • entry (String) - 通往 scs 文件的路径,或 data 如果来源不是文件
    • start (数目) - 在汇编之前的日期.现在()
    • end (数量) - 汇编后的日期.now()
    • duration (数目) - 结束 - 说吧 开始
    • includedFiles (Array) - 绝对路径到所有相关的 scs 文件,没有特定的顺序.

实例

var sass = require('node-sass');
sass.render({
  file: '/path/to/myFile.scss',
  data: 'body{background:blue; a{color:black;}}',
  importer: function(url, prev, done) {
    // url is the path in import as is, which LibSass encountered.
    // prev is the previously resolved path.
    // done is an optional callback, either consume it or return value synchronously.
    // this.options contains this options hash, this.callback contains the node-style callback
    someAsyncFunction(url, prev, function(result){
      done({
        file: result.path, // only one of them is required, see section Special Behaviours.
        contents: result.data
      });
    });
    // OR
    var result = someSyncFunction(url, prev);
    return {file: result.path, contents: result.data};
  },
  includePaths: [ 'lib/', 'mod/' ],
  outputStyle: 'compressed'
}, function(error, result) { // node-style callback from v3.0.0 onwards
  if (error) {
    console.log(error.status); // used to be "code" in v2x and below
    console.log(error.column);
    console.log(error.message);
    console.log(error.line);
  }
  else {
    console.log(result.css.toString());

    console.log(result.stats);

    console.log(result.map.toString());
    // or better
    console.log(JSON.stringify(result.map)); // note, JSON.stringify accepts Buffer too
  }
});
// OR
var result = sass.renderSync({
  file: '/path/to/file.scss',
  data: 'body{background:blue; a{color:black;}}',
  outputStyle: 'compressed',
  outFile: '/to/my/output.css',
  sourceMap: true, // or an absolute or relative (to outFile) path
  importer: function(url, prev, done) {
    // url is the path in import as is, which LibSass encountered.
    // prev is the previously resolved path.
    // done is an optional callback, either consume it or return value synchronously.
    // this.options contains this options hash
    someAsyncFunction(url, prev, function(result){
      done({
        file: result.path, // only one of them is required, see section Special Behaviours.
        contents: result.data
      });
    });
    // OR
    var result = someSyncFunction(url, prev);
    return {file: result.path, contents: result.data};
  }
});

console.log(result.css);
console.log(result.map);
console.log(result.stats);

特殊行为

  • 如果两者兼有 file 财务报告和审定财务报表 data 选项设置,节点ass将优先使用 data 和使用情况 file 在源图中计算路径.

版本信息 (QQ v 2. 0

两者 node-sass 财务报告和审定财务报表 libsass 版本信息现在通过 info 方法 :

var sass = require('node-sass');

console.log(sass.info);

/*
  it will output something like:

  node-sass       2.0.1   (Wrapper)       [JavaScript]
  libsass         3.1.0   (Sass Compiler) [C/C++]
*/

从节点 -sass >=v3.0.0起. LibSass版本在运行时确定.

一体化

列出社区在建设工具和框架中使用节点吸管的情况.

括号扩展名

@ jasonsanjose (英语) 创建了 括号 基于节点ass的扩展名 : https://github.com/jasonsanjose/brackets-sass (中文(简体) )。编辑 Sass 文件时,扩展会编辑保存时的更改。 扩展也与Live Preview集成,以显示浏览器中的 Sass 变化而无需保存或编译.

布鲁奇插件

布鲁奇官方的sass插件默认使用节点-sass,如果检测到使用Compass,则自动倒回红宝石: https://github.com/brunch/sass-brunch 互联网档案馆的存檔,存档日期2014-12-21

连接/ 执行中间软件

编译 .scss 用于连接和表达基于 http 服务器的文件.

此功能已移动到 node-sass-middleware 在节点-ass v1.0.0 中

DocPad 插件

@ 10xLaCroix 饮用器 写了一个 文档 编译插件 .scss 使用节点ass的文件 : https://github.com/docpad/docpad-plugin-nodesass 页面存档备份,存于互联网档案馆

Duo.js 扩展名

@ stephenway (英语) 创建了一个扩展,将 Sass 转换为 CSS ,使用节点- sass 与 双人 https://github.com/duojs/sass (中文(简体) )

Grunt 扩展名

@sindresorhus (英语) 已经根据节点- sass 创建了一组 grunt 任务 : https://github.com/sindresorhus/grunt-sass 互联网档案馆的存檔,存档日期2013-12-21

Gulp 扩展

@dlmanning (英语) 基于节点- sass 创建了 gulp sass 插件 : https://github.com/dlmanning/glulp-sass (中文(简体) )

枪声

@ sintaxi哈普网络服务器默认编译 .scss 使用节点ass的文件 : https://github.com/sintaxi/harp (中文(简体) )

金属匠插件

@史蒂文肖伯特 基于节点- sass 创建了金属匠插件 : https://github.com/stevenschobert/ 金属匠-驴子

气象插件

@ 四七 基于节点-ass创建了流星插件 : https://github.com/ 四七/meteor-scs (中文(简体) )

米莫萨模块

@dbashford (英语) 创建了用于 sass 的 Mimosa 模块,其中包括 节点- sass : https://github.com/dbashford/mimosa-ass 互联网档案馆的存檔,存档日期2014-12-21

示例应用

这里还有一个连接应用程序的例子: https://github.com/andrew/node-sass-example (原始内容存档于2017-09-27)

重建二进制

节点-ass包括用于流行平台的预编译二进制,用于为您的平台添加二进制遵循这些步骤:

检查项目:

git clone --recursive https://github.com/sass/node-sass.git
cd node-sass
npm install
node scripts/build -f  # use -d switch for debug release
# if succeeded, it will generate and move
# the binary in vendor directory.

命令行接口

命令行使用的接口在此阶段相当简单,如下用法部分所见.

如果 --output 旗被省略.

使用量

node-sass [options] <input> [output] 或者说: cat <input> | node-sass > output

示例

node-sass src/style.scss dest/style.css

选项 :

    -w, --watch                Watch a directory or file
    -r, --recursive            Recursively watch directories or files
    -o, --output               Output directory
    -x, --omit-source-map-url  Omit source map URL comment from output
    -i, --indented-syntax      Treat data from stdin as sass code (versus scss)
    -q, --quiet                Suppress log output except on error
    -v, --version              Prints version info
    --output-style             CSS output style (nested | expanded | compact | compressed)
    --indent-type              Indent type for output CSS (space | tab)
    --indent-width             Indent width; number of spaces or tabs (maximum value: 10)
    --linefeed                 Linefeed style (cr | crlf | lf | lfcr)
    --source-comments          Include debug info in output
    --source-map               Emit source map
    --source-map-contents      Embed include contents in map
    --source-map-embed         Embed sourceMappingUrl as data URI
    --source-map-root          Base path, will be emitted in source-map as is
    --include-path             Path to look for imported files
    --follow                   Follow symlinked directories
    --precision                The amount of precision allowed in decimal numbers
    --error-bell               Output a bell character on errors
    --importer                 Path to .js file containing custom importer
    --functions                Path to .js file containing custom functions
    --help                     Print usage info

这个 input 可以是单人 .scss 或者说 .sass,或目录。 如果输入是目录,则 --output 还必须提供旗帜.

此外,说明 --importer 将(绝对或相对 pwd) 路径取入 js 文件, 需要默认 module.exports 设置为导入函数。 看我们的考验 固定装置 举个例子.

这个 --source-map 选项接受布尔值,在这种情况下,它以 .css.map。它也接受路径 .map 文件甚至想要的目录的路径. 编译目录时 --source-map 可以是布尔值,也可以是目录.

二进制配置参数

节点-ass支持不同的配置参数来改变与sass 二进制相关的设置,如二进制名称,二进制路径或替代下载路径等. 以下参数由节点-ass支持:

可变名称.npmrc 参数进程参数数值
萨斯克语 柏林 纳斯ass 二进制 name--ass-二进制名称路径
(原始内容存档于2018-09-31) (中文(简体) ). SASSass 二进制 site--ass-二进制网站網址
萨斯巴达克语NAMEass 二进制 path-- ass- 二进制路径路径
(简体中文)ass 二进制 dir--ass- 二进制目录路径
获得授权ass reject 未授权--ass-reject-未授权价值

这些参数可用作环境变量:

  • 举个例子. export SASS_BINARY_SITE=http://example.com/

作为地方或全球 .npmerc (英语) 配置文件 :

  • 举个例子. sass_binary_site=http://example.com/

作为进程论据:

  • 举个例子. npm install node-sass --sass-binary-site=http://example.com/

如果您正在使用自签名的证书进行二进制 SASS_REJECT_UNAUTHORIZED 将覆盖( 拒绝 ) [https://nodejs.org/docs/latest/api/tls.html#tls tls createserver options securityconnectionlistener 互联网档案馆的存檔,存档日期2014-12-11[ [ ] [ ] ]. ].

安装后构建

安装只运行两个 Mocha 测试以查看您的机器能否使用预建的 属性 这将在安装期间节省一些时间。 如果任何测试失败,它将从源头建立起来.

维护者

本单元由下列人员带给你并维护:

贡献者

我们只有3个贡献者! 我们特别感谢所有那些在一段时间内在这个项目上工作的人,我们非常赞赏你的辛勤工作。 你们可以找到 这些人的完整名单.

关于补丁/ pulll 请求的说明

看看我们 贡献指南

版权 (c)2015 安德鲁·内斯比特. 见 自由主义 详细情况.

版本与发布记录

@bigcommerce/node-sass 共发布 3 个版本,首次发布于 2025/10/31;过去 12 个月发布了 0 个版本。

版本发布日期距今
10.0.2latest2025/11/041 年前
10.0.12025/11/041 年前
10.0.02025/10/311 年前

关于 @bigcommerce/node-sass 的常见问题

@bigcommerce/node-sass 是什么?

环绕自来水

如何安装 @bigcommerce/node-sass?

在项目目录运行 npm install @bigcommerce/node-sass,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 node-sass,可以用 npx node-sass 直接运行。

@bigcommerce/node-sass 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bigcommerce__node-sass 是否存在。

@bigcommerce/node-sass 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bigcommerce/node-sass 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bigcommerce/node-sass 可以商用吗?

@bigcommerce/node-sass 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bigcommerce/node-sass 的下载量有多少?

根据 npm 官方下载统计,@bigcommerce/node-sass 在 2026/10/08 – 2026/11/06 这 30 天内被下载 6,173 次,日均约 206 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bigcommerce/node-sass 还在维护吗?

最新版本 10.0.2 发布于 2025/11/04(1 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/10/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。