Unexpected token: name (DocumentAttributes) with webpack and UglifyJs

荒凉一梦 提交于 2021-01-29 15:49:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!