在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jlouns/gulp-requirejs-optimize开源软件地址(OpenSource Url):https://github.com/jlouns/gulp-requirejs-optimize开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-requirejs-optimizeOptimize AMD modules in javascript files using the requirejs optimizer. Install$ npm install --save-dev gulp-requirejs-optimize UsageSimplevar gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');
gulp.task('scripts', function () {
return gulp.src('src/main.js')
.pipe(requirejsOptimize())
.pipe(gulp.dest('dist'));
}); Custom optionsgulp-requirejs-optimize accepts almost all of the same options as r.js optimize (see below). var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');
gulp.task('scripts', function () {
return gulp.src('src/main.js')
.pipe(requirejsOptimize({
optimize: 'none',
insertRequire: ['foo/bar/bop'],
}))
.pipe(gulp.dest('dist'));
}); Multiple ModulesEach file passed to the plugin is optimized as a separate module. var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');
gulp.task('scripts', function () {
return gulp.src('src/modules/*.js')
.pipe(requirejsOptimize())
.pipe(gulp.dest('dist'));
}); Options generating functionOptions can also be specified in the form of an options-generating function to generate custom options for each file passed. This can be used to apply custom logic while optimizing multiple bundles or modules in an app. var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');
gulp.task('scripts', function () {
return gulp.src('src/modules/*.js')
.pipe(requirejsOptimize(function(file) {
return {
name: '../vendor/bower/almond/almond',
optimize: 'none',
useStrict: true,
baseUrl: 'path/to/base',
include: 'subdir/' + file.relative
};
}))
.pipe(gulp.dest('dist'));
}); Sourcemaps supportThe plugin supports gulp-sourcemaps only if var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('scripts', function () {
return gulp.src('src/main.js')
.pipe(sourcemaps.init())
.pipe(requirejsOptimize())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'));
}); APIrequirejsOptimize(options)optionsOptions are the same as what is supported by the r.js optimizer except for The options parameter can be specified as a static object or an options-generating function. Options-generating functions are passed a file object and are expected to generate an options object. Differences From r.jsoutr.js supports modules and dirr.js supports an array of This means an r.js config file for optimizing multiple modules that looks like this: {
"baseUrl": "src/modules",
"dir": "dist",
"modules": [{
"name": "one"
}, {
"name": "two"
}]
} Would look like this as a gulp task with this plugin: gulp.task('scripts', function () {
return gulp.src('src/modules/*.js')
.pipe(requirejsOptimize())
.pipe(gulp.dest('dist'));
}); LicenseMIT © Jonathan Lounsbury |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论