how to implement the version control of static files
来源:互联网 发布:java中如果不用static 编辑:程序博客网 时间:2024/05/16 09:05
https://github.com/sindresorhus/gulp-rev/blob/master/integration.md 如何通过后端服务(php)做静态资源的版本化,当然也有直接通过前端构建工具静态资源版本化,
下面是angular项目,使用gulp直接实现静态资源版本化。
/*** build 时的 js 压缩, 文件 hash 地址替换*/var gulp = require('gulp');var config = require('../config').inject;var handleErrors = require('../util/handleErrors');/*** 根据文件内容生成Hash名称,映射表写入 dest/rev-manifest.json 文件中。*/gulp.task("revision", function() { var gulpif = require('gulp-if'); var rev = require('gulp-rev'); var uglify = require('gulp-uglify'); return gulp.src([config.src + "/**/*.css", config.src + "/**/*.js"]) .pipe(rev()) .pipe(gulpif(/.*?vendor[-\d\w]*\.js$/, uglify())) .pipe(gulp.dest(config.dest)) .pipe(rev.manifest()) .on('error', handleErrors) .pipe(gulp.dest(config.dest));});/*** 根据 revision 任务生成的映射表,html中引用的资源文件名称进行替换*/gulp.task("inject", ["revision"], function(){ var manifest = gulp.src(config.dest + "/rev-manifest.json"); var replacePath = require('gulp-replace-path'); var revReplace = require('gulp-rev-replace'); var path = require('path'); // 处理html中的相对路径为相对config.src的绝对路径 var replacement = function (match, __absolutePath__) { return function (match, srcStr, originPath) { if (originPath.charAt(0) === '/' || /^http/i.test(originPath)) { // absolute path return match; } else { var relative = path.relative(process.cwd() + '/' + config.src, path.dirname(__absolutePath__)); return (srcStr + "/" + path.join(relative, originPath)).replace(/\\/g, '/'); // fix windows下sep } }; }; return gulp.src(config.htmlSrc, {base: config.src}) .pipe(replacePath(/(<script[^>]*?src=['"])([^'"]*)/g, replacement)) // 替换script src .pipe(replacePath(/(<link[^>]*?href=['"])([^'"]*)/g, replacement)) // 替换 link中的 href .pipe(revReplace({manifest: manifest, canonicalUris: false})) .pipe(gulp.dest(config.htmlDest));});
0 0
- how to implement the version control of static files
- How to get Version of the application and API version
- How to implement the built in effects of DirectX.DirectSound
- How To Change the Background Color of a Tab Control
- how to get the value of an control
- How to print the content of a Rich Edit Control
- 1. How to review the version of Linux
- How to update the version of pgfplots in MiKTeX
- How to: How to disable Java Security Warning "The application requires an earlier version of Java."
- How to implement growable memory-mapped files (GMMFs) in NTFS
- how to implement the WaitForMultipleObjects in linux
- How to collect the full path name of the files in ASM diskgroups (文档 ID 888943.1)
- How to collect the full path name of the files in ASM diskgroups (文档 ID 888943.1)
- [.NET] How to implement rotate image in user control.
- How to customize the context menus of a WebBrowser control via the IDocHostUIHandler interface.
- How to Control the [Add document] button on the bottom of every view?
- How to assign the different php files
- How to show/hide a control in the Column's DataItemTemplate based on the value of another control
- table td一行不能超过三个,超过的换行
- [Android新手学习笔记05]-如何进行活动Activity之间的跳转以及数据传递
- 让你尖叫的13种思维方式
- Range和Content-Range实体头
- leetcode 74. Search a 2D Matrix
- how to implement the version control of static files
- java 低版本运行环境执行高版本编译jar包
- 版本控制之git
- 阿里云ECS服务器在Mac下远程配置ftp服务器
- 机器学习(一)win10+python3.5安装numpy+MKL、scipy、matplotlib、scikit-learn
- 小虎OS(XiaoHuOS)打造自己的RTOS,基于stc12c5a60s2(51内核)的可剥夺多任务管理操作系统
- [Android新手学习笔记06]-活动Activity生命周期
- 一个Python程序员的进化(转)
- PAT A1012. The Best Rank (25)