意外的令牌:具有webpack和UglifyJs的名称(DocumentAttributes) [英] Unexpected token: name (DocumentAttributes) with webpack and UglifyJs

查看:97
本文介绍了意外的令牌:具有webpack和UglifyJs的名称(DocumentAttributes)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docx 5.0.2版本从角度类型脚本代码生成带有图像的Word文档.使用webpack.optimize.UglifyJsPlugin.生成代码时出现此错误.意外的令牌:具有webpack和UglifyJs的名称(文档属性).我认为Uglify无法最小化或美化与docx库相关的代码.使用docx软件包的人的任何建议.

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.

在docx软件包添加到package.json之前,该版本曾经可以正常工作

Build used to work fine before docx package added to the package.json

推荐答案

此处的问题在于无法处理ES6的Uglify.我通过改用uglifyjs-webpack-plugin解决了这个问题.

The problem here is with Uglify that cannot process ES6. I solved this problem by using uglifyjs-webpack-plugin instead.

运行 npm install uglifyjs-webpack-plugin @ 1 --dev --save 我使用的是版本1,因为我使用的是旧版的webpack.

run npm install uglifyjs-webpack-plugin@1 --dev --save I'm using version 1 since I'm with an older version of webpack.

然后 const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

  test: /\.js($|\?)/i,
  sourceMap: true,
  uglifyOptions: {
    mangle: {
      keep_fnames: true,
    },
    compress: {
      warnings: false,
    },
    output: {
      beautify: false,
    },
  },
}));

这篇关于意外的令牌:具有webpack和UglifyJs的名称(DocumentAttributes)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆