【问题标题】:add variable id in script tags using grunt使用 grunt 在脚本标签中添加变量 id
【发布时间】:2015-04-14 21:47:44
【问题描述】:

我有大约 10 个文件,例如:file1.html、file2.html、fil31.html、file4.html

每个文件都包含一个带有空白 id='' 字段的开始和结束脚本标记

我想为每个文件中的所有脚本标签添加 id。

id 是文件名。

before running grunt
eg: file1.html

<script type='text/ng-template' id=''>
     <div>Couple of other dive tags</div>
</script>

after running grunt the id filed should have an if which is the file name

eg: file1.html

<script type='text/ng-template' id='file1.html'>
     <div>Couple of other dive tags</div>
</script>

我已经尝试过使用几个 grunt 包,但不知道如何让它们选择文件名并将它们添加为 id。

grunt file_append
grunt-script-link-tags

有没有人遇到过同样的问题或知道如何解决这个问题?

【问题讨论】:

标签: gruntjs grunt-contrib-concat grunt-plugins gruntfile grunt-html-build


【解决方案1】:

使用以下代码在脚本标签中动态添加 id。

Replace all the text with specified replacement using grunt replace

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多