原始碼對應
Stylus 支援根據 Sourcemap v3 規範 的基本原始碼對應
建立原始碼對應
將 --sourcemap
旗標 (或 -m
) 與 Stylus 檔案搭配使用。這將建立 style.css
檔案,以及 style.css.map
檔案,作為 style.styl
的同層檔案,並在 style.css
的底部放置原始碼對應連結至您的原始碼對應。
stylus -m style.styl
stylus -m style.styl
您也可以在監控檔案時執行此指令。例如:stylus -w -m style.styl
。這會在您每次儲存時更新您的原始碼對應。
JavaScript API
使用選項物件或布林值設定 sourcemap
設定
var stylus = require('stylus');
var style = stylus(str)
.set('filename', 'file.styl')
.set('sourcemap', options);
style.render(function(err, css) {
// generated sourcemap object
console.log(style.sourcemap);
});
var stylus = require('stylus');
var style = stylus(str)
.set('filename', 'file.styl')
.set('sourcemap', options);
style.render(function(err, css) {
// generated sourcemap object
console.log(style.sourcemap);
});
選項
`comment` Adds a comment with the `sourceMappingURL` to the generated CSS (default: `true`)
`inline` Inlines the sourcemap with full source text in base64 format (default: `false`)
`sourceRoot` "sourceRoot" property of the generated sourcemap
`basePath` Base path from which sourcemap and all sources are relative (default: `.`)
`comment` Adds a comment with the `sourceMappingURL` to the generated CSS (default: `true`)
`inline` Inlines the sourcemap with full source text in base64 format (default: `false`)
`sourceRoot` "sourceRoot" property of the generated sourcemap
`basePath` Base path from which sourcemap and all sources are relative (default: `.`)