Google 使用 ES5 严格模式关闭,即使我指定了非严格模式(在 minify-maven-plugin 配置中)

Google Closure using ES5 strict mode even though I specified non-strict mode (in minify-maven-plugin configuration)

我正在使用 com.samaxes.maven minify-maven-plugin 缩小使用某些 ES6 特性 Google Closure 支持编写的 JS 源文件集合。这是我的 POM 中的相关配置:

<!-- minify-maven-plugin: Minification using Google Closure -->
<plugin>
    <groupId>com.samaxes.maven</groupId>
    <artifactId>minify-maven-plugin</artifactId>
    <version>1.7.6</version>
    <executions>
        <!-- Creation of the common-[version].js file -->
        <execution>
            <id>common-minify</id>
            <phase>prepare-package</phase>
            <configuration>
                <charset>UTF-8</charset>
                <jsSourceDir>.</jsSourceDir>
                <jsSourceFiles>
                    ...
                </jsSourceFiles>
                <jsFinalFile>./js/common-${project.version}.js</jsFinalFile>
                <jsEngine>CLOSURE</jsEngine>
                <closureLanguageIn>ECMASCRIPT6</closureLanguageIn>
                <closureLanguageOut>ECMASCRIPT5</closureLanguageOut>
            </configuration>
            <goals>
                <goal>minify</goal>
            </goals>
        </execution>

        <!-- 2 other similarly configured executions are here. -->
        ...

    </executions>
</plugin>

问题是,当我运行这个配置的maven目标时,我得到以下错误信息:

[INFO] Creating the merged file [common-1.8.24.js].
[INFO] Creating the minified file [common-1.8.24.min.js].
Jan 03, 2017 12:03:06 PM com.google.javascript.jscomp.LoggerErrorManager println
SEVERE: [1mcommon-1.8.24.js:5577: [31mERROR[39m - object literals cannot contain duplicate keys in ES5 strict mode[0m
    supportsDataForwarding: function () {
    ^ 

这在我看来 Google Closure 正在尝试使用 ES5 严格模式进行编译,即使我在 <closureLanguageOut> 选项中指定了非严格 ECMASCRIPT5 模式(see doc here).为什么不禁用严格模式?

我遇到了同样的问题,并找到了一种方法让 minify-maven-plugin 在构建时不会失败,以防它抱怨 ES5 严格模式:

<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.6</version>
<executions>
    <execution>
        <id>default-minify</id>
        <phase>process-resources</phase>
        <configuration>
            <charset>UTF-8</charset>                
            <closureWarningLevels>
                <es5Strict>OFF</es5Strict>
            </closureWarningLevels>
            ...
        </configuration>
        <goals>
            <goal>minify</goal>
        </goals>
    </execution>
</executions>

您可以使用以下文档进一步微调 How to tell closure compiler which warnings you want。希望这有帮助:)