combine requirejs file into one file. purpose is reduce http request.
Install with npm
npm install --save-dev gulp-requirejs-combine
move config part into your gulpfile
require.config({
baseUrl: './test/base',
paths: {
jsonp: 'jsonp',
load: 'load',
xhr: 'xhr',
nonce: 'var/nonce',
rquery: 'var/rquery'
}
});
==>>
combine({
baseUrl: './test/base',
paths: {
jsonp: 'jsonp',
load: 'load',
xhr: 'xhr',
nonce: 'var/nonce',
rquery: 'var/rquery'
}
})
- base use
var gulp = require('gulp');
var del = require('del');
var combine = require('gulp-requirejs-combine');
var paths = {
js: [
'test/base/base1.js',
'test/base/base2.js'
],
complicatejs: [
'test/complicate/require.js'
]
};
gulp.task('clean', function (cb) {
del(['build'], cb);
});
var baseConfig = {
baseUrl: './test/base',
paths: {
jsonp: 'jsonp',
load: 'load',
xhr: 'xhr',
nonce: 'var/nonce',
rquery: 'var/rquery'
}
};
gulp.task('default', function () {
return gulp.src(paths.js)
.pipe(combine(baseConfig))
.pipe(gulp.dest('test/base/build'));
});
- uglify
gulp.task('test:uglify', function () {
return gulp.src(paths.js)
.pipe(combine(baseConfig))
.pipe(uglify())
.pipe(gulp.dest('test/base/build'));
});
- more demo please see gulpfile
config is base on your gulpfile path. your need to config it base on your gulpfile location.
var config={
baseUrl: './test/base',//base on where your gulpfile location.
paths: {...
}
}
- install dependencies
npm install gulp -g
npm install
- run demo
gulp
gulp test:base
gulp test:complicate
You are welcome to contribute
Any problem you can task issue or contact me :andy.lv@live.com