2

我正在尝试利用 grunt-wiredep 在 spring-boot 项目中更改我的源代码。

通过下拉 JS/CSS 和依赖项,使用 bower 可以按预期工作,并且 grunt-wiredep 将更新源代码,但由于我使用 thymeleaf 的方式,我需要用 @{URL_GOES_HERE} 包围 URL。

这可能吗?grunt-wiredep 有前缀/后缀选项吗?(到目前为止我还没有找到这个)。

电流输出

<!-- bower-js:start -->
    <script src="bower_components\bootstrap-colorpicker\js\bootstrap-colorpicker.js">
    </script>
<!-- bower-js:end -->

期望的输出:

<!-- bower-js:start -->
    <script src="@{\bower_components\bootstrap-colorpicker\js\bootstrap-colorpicker.js}">
    </script>
<!-- bower-js:end -->
4

1 回答 1

2

grunt-wiredep可以利用原版wiredep提供的任何配置选项。

在上面的链接中,您可以看到输出格式也可以配置,github 自述文件给出了将随机类附加到脚本标签的示例:

fileTypes: {
fileExtension: {
  block: /match the beginning-to-end of a bower block in this type of file/,
  detect: {
    typeOfBowerFile: /match the way this type of file is included/
  },
  replace: {
    typeOfBowerFile: '<format for this {{filePath}} to be injected>',
    anotherTypeOfBowerFile: function (filePath) {
      return '<script class="random-' + Math.random() + '" src="' + filePath + '"></script>';
    }
  }
}, //...

因此,例如,您可以像这样覆盖默认的 HTML fileExtension 配置块:

html: {
  block: /(([ \t]*)<!--\s*bower:*(\S*)\s*-->)(\n|\r|.)*?(<!--\s*endbower\s*-->)/gi,
  detect: {
    js: /<script.*src=['"]([^'"]+)/gi
  },
  replace: {
    js: '<script src="@{\\{{filePath}}}"></script>'
  }
},
于 2015-08-13T13:44:43.640 回答