This demo replaces the string @@VERSION with the current unix timestamp when
building with gulp. @@VERSION is a query parameter to bundle.js. To avoid
caching bundle.js, we add the timestamp to it during each build.
npm install
npm run build| 'use strict'; | |
| // ... |
| const gulp = require('gulp'); | |
| const replace = require('gulp-replace'); | |
| gulp.task('copy', () => { | |
| return gulp.src('bundle.js') | |
| .pipe(gulp.dest('dist')); | |
| }); | |
| gulp.task('version', () => { | |
| return gulp.src('index.html') | |
| .pipe(replace('@@VERSION', Date.now())) | |
| .pipe(gulp.dest('dist')); | |
| }); | |
| gulp.task('default', ['copy', 'version']); |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Gulp Replace Demo</title> | |
| </head> | |
| <body> | |
| <h1>Gulp Replace Demo</h1> | |
| </body> | |
| <script src="bundle.js?v=@@VERSION" charset="utf-8"></script> | |
| </html> |
| { | |
| "name": "gulp-replace-demo", | |
| "version": "1.0.0", | |
| "description": "Gulp Replace Demo", | |
| "scripts": { | |
| "build": "./node_modules/.bin/gulp" | |
| }, | |
| "author": "Mario Tacke <[email protected]>", | |
| "license": "ISC", | |
| "devDependencies": { | |
| "gulp": "^3.9.1", | |
| "gulp-replace": "^0.5.4" | |
| } | |
| } |