![](/img/trans.png)
[英]Gulp with browserify: Cannot find module src/js/main.js
[英]Gulp task to create a DEV and PROD version of main.js
進出口新的杯和一直在玩gulp-minify
和gulp-uglify
創建通過整體main.js文件gulp-requirejs
。
但是,我需要創建此main.js文件的2個版本,一個用於我的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,
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))
});
在我的.js文件中,我已將URL更新為:
currentPage == /NETStructure/g'/products/chairs.html'
但是,這似乎沒有工作。
我建議您將這些字符串保留在一個對象中,並為同一對象提供兩個不同的文件,例如:
constants.dev.js
var constants = {
chairs: '/products/chairs.html'
};
constants.prod.js
var constants = {
chairs: 'goodsandservices/products/our-chairs.html'
};
然后,您只需要包括正確的文件(或連接在閉包中的串聯文件),然后:
currentPage == constants.chairs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.