在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jorrit/gulp-requirejs开源软件地址(OpenSource Url):https://github.com/jorrit/gulp-requirejs开源编程语言(OpenSource Language):JavaScript 95.2%开源软件介绍(OpenSource Introduction):gulp-requirejsInformationA small, simple, very easy wrapper around the require.js optimizer to work with gulp.js.
InstallationSimply add $ npm install --save-dev gulp-requirejs UsageBecause the require.js optimizer (r.js) is a kind of build system in itself we can't use the The resulting stream can be treated like a regular
var gulp = require('gulp'),
rjs = require('gulp-requirejs');
gulp.task('requirejsBuild', function() {
return rjs({
baseUrl: 'root/directory/of/js/files/',
out: 'FILENAME_TO_BE_OUTPUTTED',
name: 'mainfile', // no extension
shim: {
// standard require.js shim options
},
// ... more require.js options
})
.pipe(gulp.dest('./deploy/')); // pipe it to the output DIR
}); If you use instead of out the dir option, you do not need the pipe at all, see this example in Gulp 4 syntax and mocha test: const rjs = require('gulp-requirejs');
async function requirejsBuild(cb) {
return rjs({
dir: 'deploy',
mainConfigFile: 'config.js',
path: {
'config': '../config_init'
},
modules: [{
name: 'FILENAME_TO_BE_OUTPUTTED', // no extension
include : [ .. ]
...
}]
}) ...
};
exports.requirejsBuild = requirejsBuild; Note: In order to let gulp know that the optimization completes, return the rjs stream. See requirejs.org for more information about the supported parameters. Error handlinggulp-requirejs will emit errors when you don't pass an options object, if the Source mapsWhen source maps are enabled via the r.js Use gulp-sourcemaps to process this object in your gulp configuration. var gulp = require('gulp'),
rjs = require('gulp-requirejs')
sourcemaps = require('gulp-sourcemaps');
gulp.task('requirejsBuild', function() {
return rjs({
baseUrl: 'root/directory/of/js/files/',
out: 'FILENAME_TO_BE_OUTPUTTED',
name: 'mainfile', // no extension
generateSourceMaps: true,
shim: {
// standard require.js shim options
},
// ... more require.js options
})
.pipe(sourcemaps.init({loadMaps: true})) // initialize gulp-sourcemaps with the existing map
.pipe(sourcemaps.write()) // write the source maps
.pipe(gulp.dest('./deploy/')); // pipe it to the output DIR
}); OptionsThe options object supports the same parameters as the require.js optimizer. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论