对我
maven-minify-plugin有用的解决方案是使用(groupId is
com.samaxes.maven),但 仅 在进行生产
时才 使用。使用构建属性来指定您是否处于开发模式。链接到插件
然后,您可以拥有类似的内容(我不知道freemarker,所以我只是粘贴一些JSP代码,但是我确信它可以轻松转换):
<c:choose> <c:when test="${developmentMode}"> <link rel="stylesheet" type="text/css" href="<c:url value="/css/custom1.css"/>"/> <link rel="stylesheet" type="text/css" href="<c:url value="/css/custom2.css"/>"/> <link rel="stylesheet" type="text/css" href="<c:url value="/css/another1.css"/>"/> <link rel="stylesheet" type="text/css" href="<c:url value="/css/another2.css"/>"/> <script type="text/javascript" src="<c:url value="/js/mylibrary.js"/>"></script> <script type="text/javascript" src="<c:url value="/js/more.js"/>"></script> <script type="text/javascript" src="<c:url value="/js/util.js"/>"></script> <script type="text/javascript" src="<c:url value="/js/whatever.js"/>"></script> <script type="text/javascript" src="<c:url value="/js/more.js"/>"></script> </c:when> <c:otherwise> <link rel="stylesheet" type="text/css" href="<c:url value="/css/minified.css"/>"/> <script type="text/javascript" src="<c:url value="/js/minified.js"/>"></script> </c:otherwise></c:choose>这样,在开发过程中将使用非最小化/组合式JS / css,而最小化的CSS仅在为生产而构建时使用。
编辑:这里要求的代码是在ServletContext上公开Spring定义的bean的:
<bean > <property name="attributes"> <map> <!-- Obviously this can be changed to read from properties file --> <entry key="developmentMode" value="false" /> </map> </property></bean>



