美文网首页
webpack4 less-loader配置,报错,报Unrec

webpack4 less-loader配置,报错,报Unrec

作者: wangwing | 来源:发表于2019-05-05 10:23 被阅读0次

    我的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/; const lessModuleRegex = /\.module\.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'
    ),
    },

    相关文章

      网友评论

          本文标题:webpack4 less-loader配置,报错,报Unrec

          本文链接:https://www.haomeiwen.com/subject/mrhcoqtx.html