npm - 使用node-sass和postcss autoprefixer使用npm脚本生成源映射

标签 npm node-sass postcss autoprefixer npm-scripts

在将输出从一个管道传递到另一个管道时,是否可以使用node-sass和postcss autoprefixer生成完全正常工作的源映射?我目前在package.json中具有以下内容:

"scripts": {
    "sass": "node-sass sass/app.scss --source-map true --source-map-embed true",
    "postcss:autoprefixer": "postcss --use autoprefixer -b 'last 2 versions' --map",
    "css": "npm run sass -s | npm run postcss:autoprefixer -s > css/app.css"
}

这会产生一个半工作的内联源 map ,但是原始文件的链接不正确,因此在Chrome devtools中单击它们不会加载它们(似乎将它们作为相对链接处理,然后从css文件夹中引用)。我试图通过将--source-map-contents true选项添加到node-sass来解决此问题,但是我怀疑自动前缀修复程序会出错,因为它不喜欢dataUri的行长。

理想情况下,无论如何我还是希望输出一个单独的.map文件,但是将node-sass选项设置为--source-map css/app.css.map不会写任何东西,大概是因为只有css输出到stdout了。

最佳答案

source-map和文件系统URL替换source-map-root似乎可以解决问题:

"scripts": {
    "sass": "node-sass sass/app.scss --source-map-root file://${PWD}/ --source-map-embed true",
    "postcss:autoprefixer": "postcss --use autoprefixer -b 'last 2 versions' --map",
    "css": "npm run sass -s | npm run postcss:autoprefixer -s > css/app.css"
}

仍然会很高兴知道是否可以输出单独的.map文件!

更新:

下面是RyanZim的评论推荐的使用exorcist的新package.json:
"scripts": {
    "sass": "node-sass sass/app.scss --source-map-root file://${PWD}/ --source-map-embed true",
    "postcss:autoprefixer": "postcss --use autoprefixer -b 'last 2 versions' --map",
    "css": "npm run sass -s | npm run postcss:autoprefixer -s | exorcist css/app.css.map > css/app.css"
}

关于npm - 使用node-sass和postcss autoprefixer使用npm脚本生成源映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40852946/

相关文章:

node.js - 兼容 Nexus 的存储库,用于获取 Node 和 npm 安装程序

Angular 8 : No provider for MultilevelMenuService

node.js - Docker 镜像无法在 AWS EC2 linux 上构建,但在 Windows 和 Mac 上构建时可以正常工作

node.js - NPM - 尝试安装依赖项时出现 Node sass 错误

typescript - 错误 : PostCSS received undefined instead of CSS string

node.js - 可靠的服务器(蒂姆·伯纳斯·李爵士和麻省理工学院的项目)未加载正确的配置

node.js - 我应该在 NPM package.json 中将 "start"脚本设置为什么?

gruntjs - VS 2019 gruntfile.js 使用 'sass = require(' node-sass')' 时找不到任务

twitter-bootstrap - 如何将react-bootstrap与postcss-module和react-css-module一起使用?

kotlin - 如何将 tailwindcss 添加到 KotlinJS