在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):eduardolundgren/gulp-umd开源软件地址(OpenSource Url):https://github.com/eduardolundgren/gulp-umd开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-umdThis repository provides a simple way to build your files with support for the design and implementation of the Universal Module Definition (UMD) API for JavaScript modules. These are modules which are capable of working everywhere, be it in the client, on the server or elsewhere. The UMD pattern typically attempts to offer compatibility with the most popular script loaders of the day (e.g RequireJS amongst others). In many cases it uses AMD as a base, with special-casing added to handle CommonJS compatibility. VariationsRegular Module
See more variation options that can be added as templates onto this project on the UMD (Universal Module Definition) patterns. OptionsThe following options are the ones available with the current default values: {
dependencies: function(file) {
return [];
},
exports: function(file) {
return capitalizeFilename(file);
},
namespace: function(file) {
return capitalizeFilename(file);
},
templateName: 'amdNodeWeb',
template: path.join(__dirname, 'templates/returnExports.js'),
templateSource: 'module.exports = <%= exports %>'
}
ExamplesBuild a simple moduleLet's wrap 'use strict';
function Foo() {} Then, in the gulp task: gulp.task('umd', function() {
return gulp.src('src/*.js')
.pipe(umd())
.pipe(gulp.dest('build'));
}); After build (function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Foo = factory();
}
}(this, function() {
'use strict';
function Foo() {}
return Foo;
})); Note that by default the filename Build with dependenciesLet's wrap 'use strict';
function Foo() {} Then, in the gulp task: gulp.task('umd', function(file) {
return gulp.src('src/*.js')
.pipe(umd({
dependencies: function(file) {
return [
{
name: 'moduleName1',
amd: 'moduleName1_amd',
cjs: 'moduleName1_cjs',
global: 'moduleName1_glob',
param: 'moduleName1'
},
{
name: 'moduleName2',
amd: 'moduleName2_amd',
cjs: 'moduleName2_cjs',
global: 'moduleName2_glob',
param: 'moduleName2'
}
];
}
}))
.pipe(gulp.dest('build'));
}); After build (function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['moduleName1_amd', 'moduleName2_amd'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('moduleName1_cjs'), require('moduleName2_cjs'));
} else {
root.Foo = factory(root.moduleName1_glob, root.moduleName2_glob);
}
}(this, function(moduleName1, moduleName2) {
'use strict';
function Foo() {}
return Foo;
})); The advanced configuration for the dependencies allows you to have full control of how your UMD wrapper should handle dependency names. Advanced buildLet's wrap 'use strict';
function Foo() {};
Foo.Bar = function() {}; Then, in the gulp task: gulp.task('umd', function() {
return gulp.src('src/*.js')
.pipe(umd({
exports: function(file) {
return 'Foo.Bar';
},
namespace: function(file) {
return 'Foo.Bar';
}
}))
.pipe(gulp.dest('build'));
}); After build `build/foo.js will look like: (function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Foo.Bar = factory();
}
}(this, function() {
'use strict';
function Foo() {};
Foo.Bar = function() {};
return Foo.Bar;
})); TemplatesIn order to use any of the variations defined on the UMD (Universal Module Definition) patterns repository you can use the following template keys:
You can also use umd-templates, using the Contributing
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论