我尝试找到 Maven 插件来使用 ES6 代码缩小 Javascript 文件。我尝试了 minify-maven-plugin 1.7.6 但我认为它不支持 ES6 (函数中默认参数的错误语法)。我还尝试了一些插件来将 ES6 丑化为 es5,但它也不起作用,所以也许某人也有同样的问题。最后请一些关于 fronted-maven-plugin 的简短说明如何通过 web pack 或 babel 来完成它,但我不确定我是否可以使用 Node js。
配置 minify-maven-plugin :
<executions>
<execution>
<id>default-minify</id>
<goals>
<goal>minify</goal>
</goals>
<configuration>
<cssSourceDir>static/css</cssSourceDir>
<cssSourceIncludes>
<cssSourceInclude>**/*.css</cssSourceInclude>
</cssSourceIncludes>
<jsSourceDir>static/js</jsSourceDir>
<jsSourceIncludes>
<jsSourceInclude>*.js</jsSourceInclude>
<jsSourceInclude>legacy/**/*.js</jsSourceInclude>
</jsSourceIncludes>
</configuration>
</execution>
</executions>
minfiy-maven-plugin 错误:
[ERROR] missing ) after formal parameters at lazy-module-test.js line 1572:29
function mojaFunkcja(x = 1, y, z) {
^
[ERROR] missing } after function body at lazy-module-test.js line 1572:29
function mojaFunkcja(x = 1, y, z) {
^
配置frontend-maven-plugin:
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install grunt grunt-cli grunt-contrib-uglify</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
</execution>
</executions>
<configuration>
<nodeVersion>v6.9.1</nodeVersion>
</configuration>
前端-maven-插件中的错误:
[INFO] message: 'Unexpected token operator «=», expected punc «,»',
[INFO] filename: '../../../../../../../src/main/webapp/static/js/lazy/module-test/controllers/testCtrl.js',
[INFO] line: 150,
[INFO] col: 27,
[INFO] pos: 4283 }
第 150 行:
function mojaFunkcja(x = 1, y, z) {
最佳答案
这个 Maven 插件对我来说非常有用:https://github.com/SpyrosPac/frontend-files-uglifier
它可以分别使用 Uglify.js 和 CSSO 来缩小 JS 和 CSS 文件。两者都是通过 Rhino 执行的,因此不需要 Node。
性能相当不错,尤其是当您启用仅压缩已修改资源的选项时。
关于javascript - 没有 Node js 的 ES6 或 uglify minify maven 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52392574/