Open yc0123450 opened 4 weeks ago
Hello @yc0123450. Please provide a reproduction repository or online demo. For background, see Why reproductions are required. Thanks ❤️
@chenjiahan 已经补充仓库demo地址,因为项目比较复杂,精简后没有本地运行测试,只是测试了打包后用yarn preview进行预览,控制台就能看到报错内容,打包预计2分钟。完整项目就和我描述的一样,本地运行正常,就是打包后报错。
This error is caused by the class name being compressed, To solve this problem you can set mangle.keep_fnames
false.
(Why not keep_classnames
? Because according to the browserslist you configured, class was converted into function during swc transform.)
output: {
minify: {
jsOptions: {
minimizerOptions: {
mangle: {
keep_fnames: true
}
}
}
},
},
source code:
class VectorLineModel {
constructor() {
console.log('init VectorLineModel')
}
getHighwayCodeList() {
console.log('VectorLineModel')
}
}
export default VectorLineModel
transformed:
compressed:
@9aoy thanks,set mangle.keep_fnames
is true
,Can solve my problem。It's just that the packaging volume has increased by 100+kb, but it doesn't affect its use。
Version
Details
我的项目中使用了require.context动态加载一些模块,然后默认导出给别的地方引用使用,本地运行没有问题,打包上线后报错如下图。就算改成使用import.meta.webpackContext也一样报错。动态加载的文件都会默认导出一个类似xxxModel对象,然后动态加载后全部导出,在其他地方引入对应xxxModel使用。
Reproduce link
https://gitee.com/ychaoweb/test-demo
Reproduce Steps
npm i yarn -g
yarn
yarn build
yarn preview 使用yarn进行的包管理,打包后预览就能看到报错了