在没有 Webpack 的情况下从 NPM 模块解析 Sass @import [英] resolving Sass @import from NPM module without Webpack
本文介绍了在没有 Webpack 的情况下从 NPM 模块解析 Sass @import的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法做到这一点?我讨厌巨大的路径 ../../node_modules/etc
Is there a way to do this? I hate the gigantic paths ../../node_modules/etc
我的构建工具是 NPM 脚本,我的模块打包器是 Rollup,如果这有什么不同的话.
My build tool is NPM scripts and my module bundler is Rollup, if that makes any difference.
推荐答案
对于 node-sass,您可以使用选项 --importer my-import-script.js
.我个人想使用 webpack 语法 ~module-name/style.sass
所以我将导入器定义为:
For node-sass you can use the option --importer my-import-script.js
. I personally wanted to use the webpack syntax ~module-name/style.sass
so I defined the importer as:
# my-importer-script.js
'use strict';
module.exports = function (url, prev, done) {
if (url.substring(0, 1) === '~') {
return { file: __dirname + '/node_modules/' + url.substring(1) };
} else {
return null;
}
};
这篇关于在没有 Webpack 的情况下从 NPM 模块解析 Sass @import的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文