I want to use css modules in my project, but if I set the “modules: true“ in the vue.config.js , some style from node_modules will be tranfrom,how to ignore the node_modules style?
// vue.config.js
css: {
loaderOptions: {
css: {
localIdentName: '[local]___[hash:base64:5]',
},
less: {
javascriptEnabled: true,
},
},
sourceMap: true,
modules: true
},
Some options:
Use <link rel="stylesheet"> directly in public/index.html
Use inline wepback request (import '!!vue-style-loader!css-loader!path-to-file')
Don't use modules: true, and use *.module.css for CSS modules.
Use chainWebpack to add exclude for internal rule, then add a rule for CSS in node_modules yourself.
不太明白
尤大的第4种方法可以解决,就是先把你的三方库exclude掉,然后自己去针对这个库写一下loader。
使用exclude有点问题
config.module
.rule("css")
.exclude.add(path.resolve(__dirname, "node_modules"))
.end()
.end()
.rule("includeCss")
.test(/\.css$/)
.include.add(path.resolve(__dirname, "node_modules"))
.end()
.use("css-loader")
.loader("css-loader")
.options({
sourceMap: false,
importLoaders: 1,
modules: false
});
我这样写还是没有办法引入node_modules下的css。。。有点小崩溃
Most helpful comment
Some options:
Use
<link rel="stylesheet">directly inpublic/index.htmlUse inline wepback request (
import '!!vue-style-loader!css-loader!path-to-file')Don't use
modules: true, and use*.module.cssfor CSS modules.Use
chainWebpackto add exclude for internal rule, then add a rule for CSS in node_modules yourself.