Skip to content
On this page

源映射

Stylus 根据 Sourcemap v3 规范支持基本的源映射

创建源映射

传递 --sourcemap 标志(或 -m)和一个 Stylus 文件。这将创建一个 style.css 文件,和一个 style.css.map 文件作为 style.styl 的同级文件,并在 style.css 底部放置一个指向源映射的链接。

bash
stylus -m style.styl
stylus -m style.styl

你也可以在监视文件时运行此命令。例如:stylus -w -m style.styl。这将在每次保存时更新你的源映射。

JavaScript API

使用选项对象或布尔值设置 sourcemap 设置:

js
var stylus = require('stylus');

var style = stylus(str)
  .set('filename', 'file.styl')
  .set('sourcemap', options);

style.render(function(err, css) {
  // 生成的源映射对象
  console.log(style.sourcemap);
});
var stylus = require('stylus');

var style = stylus(str)
  .set('filename', 'file.styl')
  .set('sourcemap', options);

style.render(function(err, css) {
  // 生成的源映射对象
  console.log(style.sourcemap);
});

选项

bash
`comment`     在生成的 CSS 中添加带有 `sourceMappingURL` 的注释(默认:`true`
`inline`       base64 格式内联完整源文本的源映射(默认:`false`
`sourceRoot`  生成的源映射的 "sourceRoot" 属性
`basePath`    源映射和所有源的相对基本路径(默认:`.`
`comment`     在生成的 CSS 中添加带有 `sourceMappingURL` 的注释(默认:`true`
`inline`       base64 格式内联完整源文本的源映射(默认:`false`
`sourceRoot`  生成的源映射的 "sourceRoot" 属性
`basePath`    源映射和所有源的相对基本路径(默认:`.`

Released under the MIT License.