简体   繁体   English

努力缩小和引用.min文件

[英]Grunt to minify and reference .min files

I need to: 我需要:

  1. Copy index.html to index.uncompressed.html index.html复制到index.uncompressed.html
  2. Change some the references in index.html from .js to .min.js (ie my_jsfile.js to my_jsfile.min.js ) 3) Minify index.html index.html一些引用从.js更改为.min.js (即,将my_jsfile.jsmy_jsfile.min.js )3) my_jsfile.min.js index.html

I am using Grunt. 我正在使用Grunt。

  • Number 3 is no problem. 3号没问题。
  • I assume number 1 will be easy. 我认为1号会很容易。
  • For number 2, I was planning on using some sort of Grunt editing plugin and changing all .js file references between <!-- Start Here --> and <!-- End here --> from my_jsfile.js to my_jsfile.min.js . 对于数字2,我计划使用某种Grunt编辑插件,并在<!-- Start Here --><!-- End here --><!-- End here -->之间的所有.js文件引用从my_jsfile.jsmy_jsfile.min.js

Is this the way this type of thing is done? 这是做这种事情的方式吗?

The resource I use in this situation is grunt-processhtml , which will do exactly what you're looking for. 在这种情况下,我使用的资源是grunt-processhtml ,它将完全满足您的需求。 Check out one of my repos, steady-backbone-boilerplate , where I use this to do exactly what you're describing. 签出我的仓库之一,“ 稳定骨干”样板 ,我用它来做您所描述的。

In particular, I find this is a helpful example: 特别是,我发现这是一个有用的示例:

<!-- build:[src] js/source.min.js -->
  <script data-main="js/main" src="js/vendor/require.js"></script>
<!-- /build -->

So, in development we're using the requirejs script to load all our dependencies. 因此,在开发中,我们使用requirejs脚本加载所有依赖项。 In our production index.html file, we're loading the source js file, which has been minified with the grunt-requirejs module. 在生产的index.html文件中,我们正在加载源js文件,该文件已通过grunt-requirejs模块grunt-requirejs

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

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