项目中用到了 maven 打一个前端的包,默认的时候,会将整个webapp目录下的所有文件打到一起
不过现在都用npm打包的环境下,webapp通常会包含 node_modules 目录,这个目录肯定是要不打包的
http://maven.apache.org/plugins/maven-war-plugin/plugin-info.html
从官网上找到,maven有2个相关的属性warSourceExcludes
warSourceIncludes
但是参照网上很多博客,设置都不生效
最后自己摸索出来了
1 warSourceExcludes
warSourceIncludes
是不能共存的,warSourceExcludes
会覆盖掉 warSourceIncludes
的属性,二者只能用一个
2 如果有多个目录要设置,用 ,
英文逗号分隔
如node_modules/,.idea/,build/,config/
3 如果设置了 warSourceIncludes,最好指定一下 webxml 的路径,通过<webXml>
标签对实现,
如 <webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
PS: 关键配置部分
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<warSourceIncludes>dist/</warSourceIncludes>
<webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>