Webpack加载器别名? [英] Webpack loader aliases?
问题描述
我有一个相当复杂的样式表加载程序设置:
I have a fairly complicated loader setup for style sheets:
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style",
"css?sourceMap&localIdentName=[path][name]__[local]__[hash:base64:5]!sass?outputStyle=expanded&" +
"includePaths[]=" + other stuff)
)
}
哪个好用,但有些要求我想在css-loader中添加 modules
选项,所以它看起来像这样: / p>
Which works great, but on some requires I want to add the modules
option to css-loader, so it'd look like this:
require('./foo.scss!css?modules&sourceMap&localIdentName=[path][name]__[local]__[hash...');
但我无法在这个地方做到这一点。
But I can't do this all over the place.
如何配置这个以便我可以在某些要求上启用css-loader模块标志,同时保持其余部分相同?
How can I configure this so that I can enable the css-loader modules flag on certain requires while keeping the rest of it the same?
也许像装载机'别名'之类的东西,例如 require('./ foo.scss!my-scss-with-modules-flag-alias')
?
Maybe something like a loader 'alias', e.g. require('./foo.scss!my-scss-with-modules-flag-alias')
?
我能想到的唯一解决方案是编写一个加载器,它执行语法转换,将加载器配置内联到某些需要的调用......但这很脆弱且复杂。
The only solution I can think of is writing a loader that does a syntax transform to inline the loader config into certain require calls... but that's brittle and complicated.
推荐答案
resolveLoader.alias将在这里工作。即。
resolveLoader.alias will work here. Ie.
resolveLoader: {
alias: {
'with-modules': 'loader definition goes here',
}
}
使用此配置你可以做到
require('with-modules!./foo.scss');
。
这篇关于Webpack加载器别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!