gpt4 book ai didi

javascript - 谁可以为 grunt-wiredep 生成的 URL 添加前缀和后缀?

转载 作者:行者123 更新时间:2023-11-29 21:43:16 27 4
gpt4 key购买 nike

我正在尝试利用 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 -->

最佳答案

grunt-wiredep 可以利用 original wiredep 提供的任何配置选项.

在上面的链接中你可以看到输出格式也可以配置,github readme 给出了一个将随机类附加到脚本标签的例子:

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 配置 block :

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

关于javascript - 谁可以为 grunt-wiredep 生成的 URL 添加前缀和后缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31989532/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com