我的webpack版本是 "4.29.6"
4点多版本没有dev 和 pro 两个文件了,只有webpack.config.js
所以就在这个文件配置
本来这样配置const cssRegex = /.(css|less)$/;
然后在module rules下配置
{
loader:'less-loader'
}
运行yarn start 报错"Unrecognised input"
后来参考sass配置(安装webpack后就有的,默认安装sass)以下配置就可以了
const lessRegex = /.less/;
然后在module rules下配置
{
test: lessRegex,
exclude: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
},
'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,
},
// Adds support for CSS Modules, but using SASS
// using the extension .module.scss or .module.sass
{
test: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: true,
getLocalIdent: getCSSModuleLocalIdent,
},
'less-loader'
),
},
网友评论