使用 Samaxes Minify nosuffix 覆盖原始文件 [英] Using Samaxes Minify nosuffix to overwrite original files
问题描述
我正在使用 Samaxes minify maven 插件来缩小 js 和 css 文件.该插件在创建带有缩小 js 和 css 的新文件时效果很好,但我希望缩小的文件与原始文件具有相同的名称(覆盖它们).所以我尝试在 pom.xml 中添加 nosuffix true,如下所示:
I'm using Samaxes minify maven plugin to minify js and css files. The plugin works fine in creating new files with a minifies js and css, but I'd like that the minified files will have the same name of the original files (overwriting them). So I've tried to add the nosuffix true in the pom.xml, as below:
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.2</version>
<executions>
<execution>
<id>default-minify</id>
<configuration>
<charset>UTF-8</charset>
<closureCompilationLevel>WHITESPACE_ONLY</closureCompilationLevel>
<nosuffix>true</nosuffix>
<skipMerge>true</skipMerge>
<verbose>true</verbose>
<yuiPreserveAllSemiColons>true</yuiPreserveAllSemiColons>
<webappSourceDir>${basedir}/WebContent</webappSourceDir>
<cssSourceDir>css</cssSourceDir>
<cssSourceIncludes>
<cssSourceInclude>**/*.css</cssSourceInclude>
</cssSourceIncludes>
<cssSourceExcludes>
<cssSourceExclude>**/*.min.css</cssSourceExclude>
</cssSourceExcludes>
<jsSourceDir>scripts</jsSourceDir>
<jsSourceIncludes>
<jsSourceInclude>**/*.js</jsSourceInclude>
</jsSourceIncludes>
<jsSourceExcludes>
<jsSourceExclude>**/*.min.js</jsSourceExclude>
</jsSourceExcludes>
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
</plugin>
这是 pom.xml 中的插件配置,那里的所有选项都可以正常工作(它标识源、跳过合并等),但设置为 true 的 nosuffix 不会覆盖原始文件.我不明白的是插件完全理解源和目标,它甚至记录它节省了一些空间,但输出没有缩小:
This is the plugin configuration in the pom.xml, all the options there are working fine (it identifies the sources, skips the merging, etc) but the nosuffix set to true doesn't overwrite the original files. What I don't understand is that the plugin understands perfectly the source and the destination, it even logs that it saved some space, but the output is not minified:
[INFO] Creating the minified file [/mydir/css/styles.css].
[INFO] Uncompressed size: 32490 bytes.
[INFO] Compressed size: 24188 bytes minified (5833 bytes gzipped).
我错过了什么?
推荐答案
缩小 Maven 插件 默认在 Maven 阶段运行 process-resources
.
由于您将选项 nosuffix
和 skipMerge
设置为 true
,这会导致输出文件与原始文件具有相同的路径,因此导致输出文件在 package
阶段被源文件覆盖.
Minify Maven Plugin runs during the Maven phase process-resources
by default.
Since you are setting both the options nosuffix
and skipMerge
to true
, which cause the output files to have the same path as the originals, it is causing the output files to be overridden by the source files during the phase package
.
要解决此问题,请将插件执行阶段更改为 package
:
To fix this, change the plugin execution phase to package
:
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.2</version>
<executions>
<execution>
<id>default-minify</id>
<phase>package</phase>
<configuration>
<!-- ... -->
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
</plugin>
这篇关于使用 Samaxes Minify nosuffix 覆盖原始文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!