antd 按需加载less报错
!
2
上面报错信息,配置如下:
{
"presets": ["next/babel"],
"plugins": [
"@babel/plugin-proposal-object-rest-spread",
["styled-components", { "ssr": true, "displayName": false }],
["import", { "libraryName": "antd", "libraryDirectory": "es", "style": true }]
]
}
module.exports = withPlugins([[less, {
lessLoaderOptions : {
javascriptEnabled : true
}
}], css, bundleAnalyzer], {
webpack(config) {
config.resolve.alias = {
...(config.resolve.alias || {}),
components: path.resolve('components'),
}
config.module.rules.push({
test: /\.less$/,
// exclude: [/node_modules/],
use: [
{
loader: 'less-loader',
options: {
javascriptEnabled: true,
modifyVars: themeVariables,
},
},
],
})
return config
},
下面代码可以解决!!!
module.exports = withPlugins([[less, {
lessLoaderOptions : {
javascriptEnabled : true
}
}], css, bundleAnalyzer], {
webpack(config) {
config.resolve.alias = {
...(config.resolve.alias || {}),
components: path.resolve('components'),
}
if(config.externals){
const includes = [/antd/];
config.externals = config.externals.map(external => {
if (typeof external !== 'function') return external;
return (ctx, req, cb) => {
return includes.find(include =>
req.startsWith('.')
? include.test(path.resolve(ctx, req))
: include.test(req)
)
? cb()
: external(ctx, req, cb);
};
});
}
return config
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
把
exclude: [/node_modules/],
去掉试试。