简体   繁体   English

在Grunt Build工具缩小并合并到一个文件之后,手动替换HTML脚本标签吗?

[英]Replacing HTML script tags manually after Grunt Build tools minify and concat to one file?

Using Grunt scripts to build the development files into a distribution folder. 使用Grunt脚本将开发文件构建到分发文件夹中。 During development, I have multiple different JS files I edit and import to the HTML files. 在开发过程中,我编辑了多个不同的JS文件并导入到HTML文件中。 After Grunt build, they are uglified and put into one JS file. Grunt构建后,将它们丑化并放入一个JS文件中。

However, when I do this to build the dist folder, i then have to go to the HTML files and replace the script links with the one single link. 但是,当我这样做来构建dist文件夹时,我必须转到HTML文件并将脚本链接替换为一个链接。

I could have it defaulted to the one single link, but for it to work, I have to rebuild the project every single save. 我可以将其默认设置为单个链接,但是要使其正常工作,我必须在每次保存时都重新构建项目。

Is this normal? 这正常吗? I feel like manually changing them isn't the way its suppose to be done, can scripts fix this? 我觉得手动更改它们不是应该完成的方式,脚本可以解决此问题吗?

You can replace your concat task with grunt-concat-blocks , it allows you specify the files to concat on the html it self, so as a side effect, it also changes the list to the concated file, like you requested :]. 您可以用grunt-concat-blocks替换concat任务,它允许您指定要在其自身html上进行concat的文件,因此,副作用是,它也将列表更改为简明文件,如您所要求的:]。

<!-- build:js scripts/combined.concat.min.js -->
<script type="text/javascript" src="scripts/a.js"></script>
<script type="text/javascript" src="scripts/b.js"></script>
<!-- endbuild -->

will become: 会变成:

<script type="text/javascript" src="scripts/combined.concat.min.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM