配置less hash
安装less,less-loader";在lessRegex里面配置modules,里面配置localIdentName
{
test: lessRegex,
exclude: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 3,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: {
localIdentName: '[local]___[hash:base64:5]',
},
},
'less-loader'
),
// 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,
},
配置sass hash
同理less。但最好不要同时配置less和sass。如果同时配置,且引入第三方插件及其样式,那么该插件的样式既不用less,也不能用sass,因为都会被转化。
{
test: sassRegex,
exclude: sassModuleRegex,
use: getStyleLoaders(
{
importLoaders: 3,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: {
localIdentName: '[path][name]__[local]--[hash:base64:5]'
}
},
'sass-loader'
),
// 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,
},