问题
I am using docx 5.0.2 version for generating word document with images from the angular type script code. using webpack.optimize.UglifyJsPlugin. Getting this error when building the code . Unexpected token: name (DocumentAttributes) with webpack and UglifyJs. I assume Uglify is not able to minimize or beautify code related to docx library. Any suggestions from people using the docx package.
Build used to work fine before docx package added to the package.json
回答1:
The problem here is with Uglify that cannot process ES6. I solved this problem by using uglifyjs-webpack-plugin instead.
run npm install uglifyjs-webpack-plugin@1 --dev --save
I'm using version 1 since I'm with an older version of webpack.
then const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
test: /\.js($|\?)/i,
sourceMap: true,
uglifyOptions: {
mangle: {
keep_fnames: true,
},
compress: {
warnings: false,
},
output: {
beautify: false,
},
},
}));
来源:https://stackoverflow.com/questions/61606913/unexpected-token-name-documentattributes-with-webpack-and-uglifyjs