如何使用Grunt自动引用新的(缩小的)&HTML中的JavaScript文件

How do I automatically, with Grunt, reference the new (minified & concatenated) JavaScript files in HTML?

本文关键字:HTML 中的 文件 JavaScript 缩小 Grunt 引用 何使用      更新时间:2023-09-26

我的index.html页面是这样的:

  <html>     
  <script src="js/file1.js"></script>
  <script src="js/file2.js"></script>
  <script src="js/file2.js"></script>
  </html>

使用grunt,我能够在prod/js/file.min.js中将js文件连接并缩小为一个文件。我也有一个新的index.html页在prod/index.html是缩小。

现在的问题是,这个新的index.html页面仍然引用旧的三个javascript文件,而不是新的单个javascript文件。我该如何在grunt中改变这个呢?

最终的HTML文件应该是:
  <html>     
  <script src="js/file.min.js"></script>
  </html>

可以使用grunt-processhtml插件代替

https://www.npmjs.com/package/grunt-processhtml