我的webpack版本是 "4.29.6"
4點(diǎn)多版本沒(méi)有dev 和 pro 兩個(gè)文件了甩挫,只有webpack.config.js
所以就在這個(gè)文件配置
本來(lái)這樣配置const cssRegex = /.(css|less)$/;
然后在module rules下配置
{
loader:'less-loader'
}
運(yùn)行yarn start 報(bào)錯(cuò)"Unrecognised input"
后來(lái)參考sass配置(安裝webpack后就有的贴硫,默認(rèn)安裝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'
),
},