Error: uglify threw an exception while compiling:

Error: uglify threw an exception while compiling:

我无法使用撇号资产缩小 ES6 文件。尝试使用 APOS_MINIFY=1 node app apostrophe:generation --create-bundle=prod-bundle

缩小时出现以下错误
Error: uglify threw an exception while compiling:

/home/felix/github/fullpage-cms/lib/modules/materialize/public/js/vendor/cash.js

most likely there is invalid javascript in that file:

Unexpected token: name (evt)
Line 595 col 12


    at self.minifyScript (/home/felix/github/fullpage-cms/node_modules/apostrophe/lib/modules/apostrophe-assets/index.js:1099:17)
    at /home/felix/github/fullpage-cms/node_modules/async/lib/async.js:356:13
    at Immediate.iterate [as _onImmediate] (/home/felix/github/fullpage-cms/node_modules/async/lib/async.js:262:13)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

当我将实体化缩小文件作为一个整体添加时,我没有遇到任何问题。但是整个编译的 materialize.min 文件非常庞大。所以我尝试只导入特定的组件,就像这里讨论的那样:Use Materialize as modular components。这个解决方案正是我想要的并且工作正常但我无法生成生产包。我如何实现 ES6 对撇号缩小的支持?

Apostrophe 中使用的 Uglify 版本 2.x 不一定支持 ES6 语法,但是某些受支持的浏览器(主要是 IE11)也不支持,因此无论如何您都需要转换为 ES5。

在我们自己的项目中,我们使用 Webpack 构建一个 site.js 文件,然后以正常方式将其作为资产推送到 Apostrophe。 Babel包含在Webpack配置中,以确保输出兼容IE11及以上版本,这也足以满足Uglify。

那个Webpack的配置我们没有使用任何特殊的技巧,它是将ES6+编译为ES5的典型配置。重要的是将输出文件配置为作为资产推送到 Apostrophe 的路径。然后,您可以期待开发和生产中的相同行为,即使用和不使用 Uglify 缩小。

(Apostrophe 2.x 模块附带的前端代码首先是 ES5,因此不需要这种处理。Apostrophe 3.x 将是 100% ES2015,带有 Webpack 管道尽管我们不会推动开发人员为他们的项目特定代码使用该管道 - 每个人都不可避免地需要一些自定义 Webpack 设置,因此将输出文件推送到 Apostrophe 的技术将继续非常普遍。 )