NX WebPack CSS-Loader问题
const { merge } = require('webpack-merge');
const sass = require('sass');
module.exports = (config, context) => {
return merge(config, {
module: {
rules: [
{
test: /\.sass$/i,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[local]__[hash:base64:5]'
}
}
},
{
loader: 'sass-loader',
options: {
implementation: sass
}
}
]
}
]
}
});
};
在其中有React Project的新鲜生成的NX工作区。 试图制作自定义的webpack.config以通过SASS文件生成哈希,
但是有很多错误掉落了。
我也尝试配置巴别尔。添加了插件babel-plugin-reactct-css模型,这无济于事
const { merge } = require('webpack-merge');
const sass = require('sass');
module.exports = (config, context) => {
return merge(config, {
module: {
rules: [
{
test: /\.sass$/i,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[local]__[hash:base64:5]'
}
}
},
{
loader: 'sass-loader',
options: {
implementation: sass
}
}
]
}
]
}
});
};
freshly generated nx workspace with react project in it.
trying to make a custom webpack.config to generate the hashes via sass files
but there is a lot of errors falling down.
Also i tried configure the babel. Added the plugin babel-plugin-react-css-modules and that's doesn't help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NX具有自己的样式加载程序,它是您合并的配置的一部分。
要解决此问题,您必须从NX Config删除该加载程序。我通过循环浏览所有
module.rules
并忽略我不想要的任何一个。因此,要解决您的问题,您将这样做:这花了我很长时间来弄清楚。根据您的NX版本,您的CSS规则可能有所不同。只需
console.log(rule.test)
检查您要忽略的规则是什么。NX has it's own style-loader which is part of the config which You are merging.
To resolve this, You will have to remove that loader from NX config. I did it manually by looping through all of the
module.rules
and ignoring whichever I don't want. So to fix Your issue, You would do it this way:This took me a long time to figure out. Your CSS rule might be different, depending on Your NX version. Just
console.log(rule.test)
to check what is the rule which You want to ignore.