【问题标题】:Can I use webjars in IntelliJ without building the project?我可以在 IntelliJ 中使用 webjars 而不构建项目吗?
【发布时间】:2018-08-08 07:23:26
【问题描述】:

是否可以在 IntelliJ 的编译期间引用 webjar 依赖项?想象一下,我正在使用一些 CSS 或 HTML 并进行一些小调整。我不想在每次更改字体大小或颜色等时清理 -> 重建项目。我只想动态预览它们,在 IntelliJ 中。

【问题讨论】:

  • 可能会有自动构建选项。
  • 这没什么好转的.. 项目很大,所以.. 每次构建新项目都不是一个选项。我想立即刷新预览页面。
  • 目前还没有对webjars的支持,可以关注WEB-11226WEB-9621

标签: java spring intellij-idea frontend webjars


【解决方案1】:

假设您有 webjars Maven 依赖项:

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>bootstrap</artifactId>
    <version>${bootstrap.version}</version>
</dependency>
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>${jquery.version}</version>
</dependency>

您可以通过将以下代码放入&lt;head&gt;&lt;/head&gt; 内的模板中来引用您的资源:

<link href="webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" rel="stylesheet" media="screen"
            th:href="@{/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css}"/>
<script src="webjars/jquery/3.2.0/jquery.min.js"
            th:src="@{/webjars/jquery/3.2.0/jquery.min.js}"></script>

属性hrefsrc 将在编译时使用,而属性th:hrefth:scr 将由Thymeleaf 在运行时使用。

以同样的方式,您可以使用自己的样式表或脚本:

<link href="../../static/css/app.css" th:href="@{css/app.css}" rel="stylesheet" media="screen"/>
<script src="../../static/js/app.js" th:src="@{js/app.js}"></script>

【讨论】:

    猜你喜欢
    • 2015-03-09
    • 2017-07-27
    • 2018-07-20
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    相关资源
    最近更新 更多