简体   繁体   English

如何包含适当的JavaScript文件的版本(精简版还是原始版)?

[英]How to include appropriate JavaScript file's version (minified vs. raw)?

I am developing a webapp (if it matters, I use npm and bower ). 我正在开发一个webapp(如果重要的话,我使用npmbower )。 My HTML file includes angular.js . 我的HTML文件包含angular.js Now, I want that my production-version of the webapp uses the minified version angular.min.js . 现在,我希望我的angular.min.js应用程序的生产版本使用缩小的版本angular.min.js

Considering I do want two versions of my webapp: 考虑到我确实需要两个版本的Webapp:

  • A "raw" version which includes angular.js 包含angular.js “原始”版本
  • A "production" version which includes angular.min.js 包含angular.min.js “生产”版本

How is it traditionally done given that I want to maintain a single version of index.html ? 考虑到我要维护index.html的单个版本,传统上index.html

You can either do it manually or you can use Gulp or Grunt 您可以手动执行此操作,也可以使用GulpGrunt

They will help you to get your files ready for the production environment. 它们将帮助您为生产环境准备好文件。

This tutorial was a big help when I started with gulp. 当我开始使用gulp时, 本教程对您有很大帮助。

I opted for sed invoked in a Makefile : 我选择了在Makefile调用的sed

$(RELEASE_DIR)/index.html: $(PUBLIC_DIR)/index.html | $(RELEASE_DIR)/
    $(SED) 's/\.js/.min.js/g' $< > $@

$(RELEASE_DIR)/:
    $(MKDIR) --parents $@

I am accepting my own answer because it was simpler to use sed rather than using yet another dependency (I already had a Makefile ). 我接受我自己的答案,因为使用sed比使用另一个依赖项更简单(我已经有了一个Makefile )。

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

相关问题 如何在Laravel Mix生成的生产中包含缩小的javascript文件? - How to include minified javascript file in production generated by Laravel Mix? 如何自动将我的自定义javascript文件转换为压缩版本 - How to automatically convert my Custom javascript file to minified version 如何在RequireJS优化中包括缩小的库版本 - How to include minified library version in RequireJS optimization 在性能方面缩小/编译JavaScript与未压缩的JavaScript - Minified/compiled JavaScript vs. uncompressed JavaScript in terms of performance 原始javascript是否应位于.js文件中-如何包含? - Should raw javascript be in a .js file - How to include? 缩小文件(UMD,CommonJS,浏览器)中包含哪些JavaScript - Which JavaScript to include in minified file (UMD, CommonJS, Browser) 最好以php原始格式回显javascript,或者回显已缩小并压缩的脚本包括? - Is it better to echo javascript in raw format with php, or echo a script include that has been minified and gzipped? 在战争中包含缩小的JavaScript文件 - Include minified JavaScript files in war 如何推迟W3 Total Cache的缓存和缩小的javascript文件的javascript解析 - How to defer parsing of javascript of W3 Total Cache's cached & minified javascript file 何时在你的html和外部.js中包含javascript是否合适? - When is it appropriate to include javascript in your html vs an external .js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM