开发喵星球

若依集成yuicompressor实现(CSS/JS压缩)(八十一)

在Maven打包的时候可以使用YUI Compressor(压缩CSS/JS)文件,使用yuicompressor-maven-plugin插件进行压缩后会减小体积,提高请求速度。

在pom.xml文件中增加该插件的定义,示例如下:

<build>
    <plugins>
        <!-- YUI Compressor (CSS/JS压缩) -->
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.5.1</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- 读取js,css文件采用UTF-8编码 -->
                <encoding>UTF-8</encoding>
                <!-- 是否忽略警告 -->
                <jswarn>false</jswarn>
                <!-- 是否添加.min后缀 -->
                <nosuffix>true</nosuffix>
                <!-- 压缩多少字节换行 -->
                <linebreakpos>50000</linebreakpos>
                <!-- 源目录,即需压缩的根目录 -->
                <sourceDirectory>src/main/resources/static</sourceDirectory>
                <!-- 若存在已压缩的文件,会先对比源文件是否有改动。有改动便压缩,无改动就不压缩 -->
                <force>true</force>
                <includes>
                    <include>**/*.js</include>
                    <include>**/*.css</include>
                </includes>
                <excludes>
                    <exclude>**/*.min.js</exclude>
                    <exclude>**/*.min.css</exclude>
                    <exclude>**/fileinput.js</exclude>
                    <exclude>**/bootstrap-treetable.js</exclude>
                </excludes>
            </configuration>
        </plugin> 
    </plugins>
</build>
   
分类:Java/OOP 作者:无限繁荣, 吴蓉 发表于:2023-12-27 09:55:33 阅读量:178
<<   >>


powered by kaifamiao