Gulp任务创建main.js的DEV和PROD版本 [英] Gulp task to create a DEV and PROD version of main.js
问题描述
我是Gulp的新成员,并且一直在玩 gulp-minify
和 gulp-uglify
来创建整体主要.js文件通过 gulp-requirejs
。
然而,我需要创建2个版本的main.js文件,一个用于我的DEV环境,另一个用于PROD。
原因是,在某些.js文件中,我列出了URL,例如:
currentPage =='/products/chairs.html'
但是,将这些html文件移动到我的.Net结构中时,实际的URL为:
currentPage =='goodsandservices / products / our-chairs.html'
我目前的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))
});
我尝试过使用gulp-replace,并将我的rjs任务更新为:
gulp.task('rjs',function(){
rjs({
baseUrl:config.src .js,
出:'main.js',
名称:'main',
mainConfigFile:config.src.js +'/main.js',
排除: ['angular']
})
.pipe(prod?uglify({mangle:false,compress:{drop_console:true}}):gutil.noop())
.pipe替换(/ NETStructure / g,'goodsandservices'))
.pipe(gulp.dest(config.dest.js))
});
在我的.js文件中,我更新了网址:
currentPage == /NETStructure/g'/products/chairs.html'
然而,这似乎并没有起作用。
我建议你保留这些字符串在一个对象中,同一对象有两个不同的文件,例如:
constants.dev.js
var constants = {
主持人:'/products/chairs.html'
};
constants.prod.js
var常量= {
主持人:'goodsandservices / products / our-chairs.html'
};
然后你只需要包含正确的文件(或者包含在闭包中的连接) p>
currentPage == constants.chairs
Im new to Gulp and have been playing with gulp-minify
and gulp-uglify
to create an overall main.js file via gulp-requirejs
.
However, i need to create 2 versions of this main.js file, one for my DEV environment, and one for PROD.
Reason being, in some .js files, i have listed URLs, for example:
currentPage == '/products/chairs.html'
However, when moving these html files into my .Net structure, the actual URL is:
currentPage == 'goodsandservices/products/our-chairs.html'
My current rJS task is as follows:
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.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:
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
var constants = {
chairs: '/products/chairs.html'
};
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
这篇关于Gulp任务创建main.js的DEV和PROD版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!