[英]Gulp task to create a DEV and PROD version of main.js
Im new to Gulp and have been playing with gulp-minify
and gulp-uglify
to create an overall main.js file via gulp-requirejs
. 进出口新的杯和一直在玩
gulp-minify
和gulp-uglify
创建通过整体main.js文件gulp-requirejs
。
However, i need to create 2 versions of this main.js file, one for my DEV environment, and one for PROD. 但是,我需要创建此main.js文件的2个版本,一个用于我的DEV环境,一个用于PROD。
Reason being, in some .js files, i have listed URLs, for example: 原因是在某些.js文件中,我列出了URL,例如:
currentPage == '/products/chairs.html'
However, when moving these html files into my .Net structure, the actual URL is: 但是,将这些html文件移到我的.Net结构中时,实际的URL是:
currentPage == 'goodsandservices/products/our-chairs.html'
My current rJS task is as follows: 我当前的rJS任务如下:
gulp.task('rjs', function() {
rjs({
baseUrl: config.src.js,
out: 'main.js',
name: 'main',
mainConfigFile: config.src.js + '/main.js',
exclude: [ 'angular']
})
.pipe(prod ? uglify({ mangle: false, compress: { drop_console: true } }) : gutil.noop())
.pipe(gulp.dest(config.dest.js))
});
I have tried using gulp-replace, and updated my rjs task as: 我尝试使用gulp-replace,并将我的rjs任务更新为:
gulp.task('rjs', function() {
rjs({
baseUrl: config.src.js,
out: 'main.js',
name: 'main',
mainConfigFile: config.src.js + '/main.js',
exclude: [ 'angular']
})
.pipe(prod ? uglify({ mangle: false, compress: { drop_console: true } }) : gutil.noop())
.pipe(replace(/NETStructure/g, 'goodsandservices'))
.pipe(gulp.dest(config.dest.js))
});
And in my .js files, i have updated the URLs to: 在我的.js文件中,我已将URL更新为:
currentPage == /NETStructure/g'/products/chairs.html'
However this didnt appear to work. 但是,这似乎没有工作。
I suggest you to keep those strings in an object and have two different files for the same object, like: 我建议您将这些字符串保留在一个对象中,并为同一对象提供两个不同的文件,例如:
constants.dev.js constants.dev.js
var constants = {
chairs: '/products/chairs.html'
};
constants.prod.js constants.prod.js
var constants = {
chairs: 'goodsandservices/products/our-chairs.html'
};
Then you only need to include the correct file (or concatenate wrapped in a closure) and: 然后,您只需要包括正确的文件(或连接在闭包中的串联文件),然后:
currentPage == constants.chairs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.