Are you using any kind of modules? ES6 modules, AMD, CommonJS, ...?
If so, you can generate a config module with Gulp where you can inject any variable you want. It would look something like this:
config.tmpl.js
module.exports = <%= config %>
config gulp task
var gulp = require('gulp');
var template = require('gulp-template');
var rename = require('gulp-rename');
gulp.task('config', function() {
return gulp.src('path/to/config.tmpl.js')
.pipe(template({config: JSON.stringify({
timeStamp: new Date()
})}))
.pipe(rename('config.js'))
.pipe(gulp.dest('path/to/config.js'));
});
and finally, in your JS file
var config = require('path/to/config.js');
var object = {
timeStamp: config.timeStamp
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…