谁可以在grunt-wiredep生成的URL中附加前缀和后缀?

时间:2015-08-13 13:23:40

标签: javascript thymeleaf grunt-wiredep

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

使用bower通过拉下JS / CSS和依赖项按预期工作,grunt-wiredep将更新源代码,但由于我使用百里香叶的方式,我需要用@ {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 -->

1 个答案:

答案 0 :(得分:2)

grunt-wiredep可以使用original 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>'
  }
},