3

静的コンテンツを縮小するために wro4j を使用しています。ただし、開発環境では、圧縮されていないバージョンの JS および CSS ファイルを使用したいと考えています。

コンテキストに入れるために、Spring Boot と Thymeleaf を使用しています。

<head></head>このコードは、HTML内では機能しません:

<th:block th:if="${@environment.getActiveProfiles()[0] != 'development'}">
    <link th:href="@{/wro4j/compressed.css}" rel="stylesheet"></link>
</th:block>
<th:block th:if="${@environment.getActiveProfiles()[0] == 'development'}">
    <link th:href="@{/css/uncompressed.css}" rel="stylesheet"></link>
</th:block>

私のHTMLのソースで上記のコードから私が見るものは次のとおりです。

<link rel="stylesheet" href="/wro4j/compressed.css" />

<link rel="stylesheet" href="/css/uncompressed.css" /> 

「application.yml」でプロファイルを開発用に設定しているため、含める必要がある css は uncompressed.css だけです。

ただし、次のようなことを行うと、<body></body>期待どおりに完全に機能します。

<th:block th:if="${@environment.getActiveProfiles()[0] == 'development'}">
    <div th:text="${@environment.getActiveProfiles()[0]}"></div>
</th:block>
<th:block th:if="${@environment.getActiveProfiles()[0] != 'development'}">
    <div th:text="'WHAT THE HECK!' + ${@environment.getActiveProfiles()[0]"></div>
</th:block>

春のプロファイルを で開発に設定したのでapplication.yml、後者のブロックから期待されるのは「開発」であり、「なんてこった!開発」ではなく、まさにそれが私が見ているものです。では、HTML の head セクションで同じコードが期待どおりに動作しないのはなぜですか。

私は何が欠けていますか?

4

1 に答える 1

1

私の質問に対する@Borisのコメントのおかげで、解決策はThymeleafバージョン3を使用することです.しかし、回避策として、これは私が当分の間行ったことです:

<link th:if="${@environment.getActiveProfiles()[0] != 'development'}"  th:href="@{/wro4j/all.css}" rel="stylesheet" />

<script  th:if="${@environment.getActiveProfiles()[0] == 'development'}" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
于 2016-06-10T12:20:46.443 に答える