共计 1217 个字符,预计需要花费 4 分钟才能阅读完成。
webpack 这些年遇到的报错
1.
这个问题是因为 webpack 版本不同导致的写法谬误
批改前代码:
options: {
modules: true, // 以前的版本设置 modules 为 true,而后其余属性和 modules 同级
getLocalIdent: (context, localIdentName, localName) => {
if (context.resourcePath.includes('node_modules') ||
context.resourcePath.includes('ant.design.pro.less') ||
context.resourcePath.includes('global.less')
) {return localName;}
const match = context.resourcePath.match(/src(.*)/);
if (match && match[1]) {const antdProPath = match[1].replace('.less', '');
const arr = slash(antdProPath)
.split('/')
.map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(
/--/g,
'-',
);
}
return localName;
},
},
批改后代码:
modules: {// 属性都写在 modules 外面
getLocalIdent: (context, localIdentName, localName) => {
if (context.resourcePath.includes('pages') ||
context.resourcePath.includes('node_modules') ||
context.resourcePath.includes('ant.design.pro.less') ||
context.resourcePath.includes('global.less')
) {return localName;}
const match = context.resourcePath.match(/src(.*)/);
if (match && match[1]) {const antdProPath = match[1].replace('.less', '');
const arr = slash(antdProPath)
.split('/')
.map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(
/--/g,
'-',
);
}
return localName;
},
},
正文完