gpt4 book ai didi

javascript - 使用 Maven 插件缩小 CSS 和 JS 文件不起作用

转载 作者:行者123 更新时间:2023-11-29 23:56:53 26 4
gpt4 key购买 nike

我正在尝试按照 http://www.baeldung.com/maven-minification-of-js-and-css-assets 中的说明在我的 Spring MVC Web 应用程序中使用 YUI 压缩器 maven 插件。 .我已将以下内容添加到我的 pom.xml 文件中:

   <plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
<webappDirectory>${project.build.directory}/min</webappDirectory>
<excludes>
<exclude>**/*.min.js</exclude>
<exclude>**/handlebars-3133af2.js</exclude>
<exclude>**/require.js</exclude>
</excludes>
</configuration>
</plugin>

我在 src/main/webapp 下的子文件夹中有很多 CSS 和 JS 文件,根据文档,所有这些都应该被缩小。但是当我运行 maven clean install 时,我既没有在我的控制台中看到任何与缩小相关的日志,也没有在我的 war 文件中找到任何缩小的文件。

我只想将缩小后的文件保存在名为 min 的子文件夹下,并在与现有 CSS 或 JS 文件相同的文件夹中保存相同的文件名

控制台日志现在是:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building smartwcm-services 6.3.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ smartwcm-services ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 36 resources
[INFO]
[INFO] --- yuicompressor-maven-plugin:1.5.1:compress (default) @ smartwcm-services ---
[ERROR] E:\projects\smartwcm\source-code\smartwcm-services\src\main\webapp\layout\common\adminv3\ca\css\content\design\azure.js [1:2]: illegal character
[ERROR] ...E:\projects\smartwcm\source-code\smartwcm-services\src\main\webapp\layout\common\adminv3\ca\css\content\design\azure.js:line 1:column 2:illegal character
/* Note: jquery script is assumed to be loaded prior to this script */
[ERROR] E:\projects\smartwcm\source-code\smartwcm-services\src\main\webapp\layout\common\adminv3\ca\css\content\design\azure.js [1:2]: syntax error
[ERROR] ...E:\projects\smartwcm\source-code\smartwcm-services\src\main\webapp\layout\common\adminv3\ca\css\content\design\azure.js:line 1:column 2:syntax error
/* Note: jquery script is assumed to be loaded prior to this script */
[ERROR] E:\projects\smartwcm\source-code\smartwcm-services\src\main\webapp\layout\common\adminv3\ca\css\content\design\azure.js [1:3]: illegal character
[ERROR] ...E:\projects\smartwcm\source-code\smartwcm-services\src\main\webapp\layout\common\adminv3\ca\css\content\design\azure.js:line 1:column 3:illegal character
/* Note: jquery script is assumed to be loaded prior to this script */
[ERROR] E:\projects\smartwcm\source-code\smartwcm-services\src\main\webapp\layout\common\adminv3\ca\css\content\design\azure.js [1:0]: Compilation produced 3 syntax errors.
[ERROR] ...E:\projects\smartwcm\source-code\smartwcm-services\src\main\webapp\layout\common\adminv3\ca\css\content\design\azure.js:line 1:column 0:Compilation produced 3 syntax errors.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.060 s
[INFO] Finished at: 2016-12-29T11:25:32+05:30
[INFO] Final Memory: 19M/111M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:yuicompressor-maven-plugin:1.5.1:compress (default) on project smartwcm-services: Execution default of goal net.alchim31.maven:yuicompressor-maven-plugin:1.5.1:compress failed: Compilation produced 3 syntax errors. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

最佳答案

如果你在没有 nosuffix 的情况下运行pom.xml 中的选项就像您发布的配置一样,您将在 target\min 文件夹中获得最小化的文件。你会看到下面登录maven

[INFO] --- yuicompressor-maven-plugin:1.5.1:compress (default) @ spring-static-resources ---
[INFO] bootstrap.css (127343b) -> bootstrap-min.css (106005b)[83%]
[INFO] foo.js (44b) -> foo-min.js (37b)[84%]
[INFO] utils.js (48b) -> utils-min.js (28b)[58%]
[INFO] main.js (138b) -> main-min.js (100b)[72%]
[INFO] router.js (86b) -> router-min.js (64b)[74%]
[INFO] bootstrap.css (127343b) -> bootstrap-min.css (106005b)[83%]
[INFO] foo.js (44b) -> foo-min.js (37b)[84%]
[INFO] bootstrap.css (127343b) -> bootstrap-min.css (106005b)[83%]
[INFO] myCss.css (127343b) -> myCss-min.css (106005b)[83%]
[INFO] bootstrap.css (127343b) -> bootstrap-min.css (106005b)[83%]
[INFO] total input (637075b) -> output (530291b)[83%]

当您使用 <nosuffix>true</nosuffix> 运行时你会得到低于日志。此选项会在 target\min 文件夹中为您提供缩小的文件,但会保持文件名不变。

[INFO] --- yuicompressor-maven-plugin:1.5.1:compress (default) @ spring-static-resources ---
[INFO] bootstrap.css (127343b) -> bootstrap.css (106005b)[83%]
[INFO] foo.js (44b) -> foo.js (37b)[84%]
[INFO] utils.js (48b) -> utils.js (28b)[58%]
[INFO] main.js (138b) -> main.js (100b)[72%]
[INFO] router.js (86b) -> router.js (64b)[74%]
[INFO] bootstrap.css (127343b) -> bootstrap.css (106005b)[83%]
[INFO] foo.js (44b) -> foo.js (37b)[84%]
[INFO] bootstrap.css (127343b) -> bootstrap.css (106005b)[83%]
[INFO] myCss.css (127343b) -> myCss.css (106005b)[83%]
[INFO] bootstrap.css (127343b) -> bootstrap.css (106005b)[83%]
[INFO] total input (637075b) -> output (530291b)[83%]

要在 war 中包含这些最小化文件而不是原始文件,您需要设置 <webappDirectory>在 pom.xml 中。所以你的配置应该如下所示

 <plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>${yuicompressor-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
<webappDirectory>${project.build.directory}/min</webappDirectory>
<excludes>
<exclude>**/*.min.js</exclude>
<exclude>**/handlebars-3133af2.js</exclude>
<exclude>**/require.js</exclude>
</excludes>
</configuration>
</plugin>

以上日志来自github项目https://github.com/eugenp/tutorials/tree/master/handling-spring-static-resources .检查 pom.xml 以供在此项目中引用。

关于javascript - 使用 Maven 插件缩小 CSS 和 JS 文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41372708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com