{ test: cssRegex, exclude: cssModuleRegex, use: getStyleLoaders({ importLoaders: 1, sourceMap: isEnvProduction && shouldUseSourceMap, modules:false }), // Don‘t consider CSS imports dead code even if the // containing package claims to have no side effects. // Remove this when webpack adds a warning or an error for this. // See https://github.com/webpack/webpack/issues/6571 sideEffects: true, },
其中
modules:false是不启用局部样式,如果设置成true,就会为当前引入CSS的文件启用局部样式,比如:
这样的写法运行后,就会发现CSS引入的类已经被编译成一个独一无二的类名了,不会穿透子组件进行CSS干扰,更多详细内容,可以参考这个文章:
https://www.jianshu.com/p/f8b73cfc6ec8