mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
Added build option to wrap in UMD declaration. issue #34
This commit is contained in:
parent
f36a8273a1
commit
8890b30685
@ -11,6 +11,15 @@
|
|||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
(function (root, factory) {
|
||||||
|
if (typeof define === 'function' && define.amd) {
|
||||||
|
// AMD. Register as an anonymous module.
|
||||||
|
define(factory);
|
||||||
|
} else {
|
||||||
|
// Browser globals
|
||||||
|
root.dat = factory();
|
||||||
|
}
|
||||||
|
}(this, function () {
|
||||||
/** @namespace */
|
/** @namespace */
|
||||||
var dat = dat || {};
|
var dat = dat || {};
|
||||||
|
|
||||||
@ -3670,3 +3679,5 @@ dat.dom.CenteredDiv = (function (dom, common) {
|
|||||||
dat.utils.common),
|
dat.utils.common),
|
||||||
dat.dom.dom,
|
dat.dom.dom,
|
||||||
dat.utils.common);
|
dat.utils.common);
|
||||||
|
return dat;
|
||||||
|
}));
|
||||||
|
@ -4,5 +4,8 @@ require('./builder.js').build({
|
|||||||
"out": "../build/dat.gui.js",
|
"out": "../build/dat.gui.js",
|
||||||
"minify": false,
|
"minify": false,
|
||||||
"shortcut": "dat.GUI",
|
"shortcut": "dat.GUI",
|
||||||
"paths": {}
|
"paths": {},
|
||||||
|
"umd": {
|
||||||
|
ret: 'dat'
|
||||||
|
}
|
||||||
});
|
});
|
@ -110,6 +110,10 @@ function build(_params) {
|
|||||||
|
|
||||||
to_write += params.shortcut + ' = ' + params.main.replace(/\//g, '.') + ' = ' + defined[params.main].getClosure() + ';';
|
to_write += params.shortcut + ' = ' + params.main.replace(/\//g, '.') + ' = ' + defined[params.main].getClosure() + ';';
|
||||||
|
|
||||||
|
if ( params.umd ){
|
||||||
|
to_write = wrap_umd( params.shortcut.split('.')[0], to_write + '\nreturn '+params.umd.ret+';' );
|
||||||
|
}
|
||||||
|
|
||||||
if (params.verbose) console.log('Exported: ' + params.main + ' to window.' + params.shortcut);
|
if (params.verbose) console.log('Exported: ' + params.main + ' to window.' + params.shortcut);
|
||||||
|
|
||||||
if (params.minify) {
|
if (params.minify) {
|
||||||
@ -226,6 +230,29 @@ function define(deps, callback) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap the source code in a UMD declaration
|
||||||
|
* @param {String} name The root namespace (for browser global definition)
|
||||||
|
* @param {String} src Source code text
|
||||||
|
* @return {String}
|
||||||
|
*/
|
||||||
|
function wrap_umd( name, src ){
|
||||||
|
|
||||||
|
return [
|
||||||
|
"(function (root, factory) {",
|
||||||
|
" if (typeof define === 'function' && define.amd) {",
|
||||||
|
" // AMD. Register as an anonymous module.",
|
||||||
|
" define(factory);",
|
||||||
|
" } else {",
|
||||||
|
" // Browser globals",
|
||||||
|
" root."+ name +" = factory();",
|
||||||
|
" }",
|
||||||
|
"}(this, function () {",
|
||||||
|
src.replace(/\n/g,'\n '),
|
||||||
|
"}));\n"
|
||||||
|
].join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
function file_exists(path) {
|
function file_exists(path) {
|
||||||
try {
|
try {
|
||||||
var stats = fs.lstatSync(path)
|
var stats = fs.lstatSync(path)
|
||||||
|
Loading…
Reference in New Issue
Block a user