Synopsis
The Brace Suite | Ubuntu on Windows |
---|---|
![]() |
![]() |
Brace Umd help pages
- Synopsis
- Contibutors
- Specification
- Using the project
More than a unified module definition
Brace Umd is a source-building platform to support AMD (asynchronous module definition) modules built by the RequireJs optimizer. There will be no further need to handle individual license insertions in build files or if individual modules will be working after project obfuscations. Brace Umd ensures optimal, finished and deterministic deployments of large multi-library javscript bundles.
How it works
Individual amd modules sit above Brace Umd as a dependency descendant which holds the optimization build information. The module is then built, tested and distributed with this known optimization build output. Other projects can then be compiled using their own optimizations provied by Brace Umd while not altering the external dependecy build. Then the umd wrapper is applies to the project build for deployment. This makes for consistent package builds which consist of multiple packages and modules without need of dependency optimizing.
The Brace Umd wrapper is better than other unified module definition wrappers by providing localized uglify-js functionality and option passing. This allows the umd wrap to only ever be inserted once while using projects which also are umd wraped.
Licensed under: MIT WITH BSD-2-Clause This project relies heavily on (and includes) the Uglify-js source code. Kodos, to the Uglify-js team!
Bonuses:
- Enables cross-platform module bundling when used with the r.js optimizer and the built in factory loader
- Provides an anonymous module option for amdefine to avoid its dependency conundrum.
- The wrapper only adds only one new namespace (umd), by using a self-destructing proxy method
- Provides a way to switch between definition types without altering source code
- Allows for minification of wrapped source code using almost all of the uglify-js options
- Well commented, professionally engineered and thoroughly documented code
- Vast and deep unit tests on Windows 10 and Ubuntu 18
Note: it is acceptable to use mangle and mangle properties with the Umd source and in the requirejs optimizing process. This is done by storing the build config options used and then passing them back into uglify-js via the r.js build config file (see using with requirejs, for more information.
The build process involves two RequireJs configuration files to operate. The code below is for quick access and convenience. See help document pertaining to Requirejs configurations for more information.
// Project optimization r_js file: "_init": modulepaths "name": "out": +".js" "baseUrl": "lib" { // This is how a module is built which has dependency modules which use brace_umd. The non-brace_umd module version is used instead when a module is // loaded which was a brace_umd built module (it will contain a _umd.js suffix). It is assumed that any module which contains a _umd.js suffix is // a brace_umd wrapped module. Note: this should only apply when using a require.resolve as a requirejs paths value. return /.+_umd\.js$/ && && || content } "paths": // Add any external packages use in this project here with an :empty value // "": "empty:" "optimize": "uglify" "uglify2": build_option "keepAmdefine": false "keepBuildDir": true "writeBuildTxt": false
// Final project assembly r_js file: "_init": modulepaths "name": "out": +configsuffix||""+".js" "baseUrl": "build" { // This is how a module is built which has dependency modules which use brace_umd. The non-brace_umd module version is used instead when a module is // loaded which was a brace_umd built module (it will contain a _umd.js suffix). It is assumed that any module which contains a _umd.js suffix is // a brace_umd wrapped module. Note: this should only apply when using a require.resolve as a requirejs paths value. return /.+_umd\.js$/ && && || content } "paths": //"": nodeRequire.resolve("").replace(/\.js\s*$/, "") "wrap": "start": configsuffix === "_umd" && wrap_start || "" // Add an anonymous definition. "end": configsuffix === "_umd" && || "" "optimize": "none" "keepAmdefine": configsuffix !== "_umd" "keepBuildDir": true "writeBuildTxt": false
Below is the complete umd script. The following code will work in nodejs or the browser and can use any of the supported definitions (even copy/pasted into the console to enable quick project experiments):
/* Generated by Brace_Umd 0.8.2 */! { var define requirejs require umd = e: 'object' == typeof module && 'filename' in module && 'exports' in module requirejs: r define: i i: 'object' == typeof t && t || {} { var e = define: !thisiauto_anonymous && thisdefine || thist requirejs: thisrequirejs || thiso require: thisrequirejs || thise && modulerequire || thisfactory factory: thisfactory ; thisiforce_type in e && erequirejs = erequire = edefine = efactory = ethisiforce_type define = edefine requirejs = erequirejs require = erequire; } n: !1 { i && iconstructor === Array ? o = t t = r r = i i = '' : 'string' != typeof i && o = r t = i r = 'require' i = ''; var n = f = umde && modulerequire || erequire u = ''; if r !0 !== umdn if !i return umdn = !0 void u ? console : umde ? moduleexports = t : t; umdn = i; umde ? moduleexportsi = t : ei = t; } f: 'config' 'nextTick' 'version' 'jsExtRegExp' 'isBrowser' 's' 'toUrl' 'undef' 'defined' 'specified' 'onError' 'createNode' 'load' 'exec' u: 'amd' 'require' { if umde && !umddefine try umddefine = modulemodule; for var e in umddefine umdte = umddefinee; catch e {} var i = umddefine || umdfactory; i == umddefine && umdiauto_anonymous ? !0 !== umdn && 'string' == typeof arguments0 ? umdn = arguments0 : 'string' != typeof arguments0 && umdn = !0 : umdt = i umd i; } { if umde try umdrequirejs = module; catch e {} umdo = umdrequirejs || umdfactory umd umdo; } ; for var o in umdu umdt; if !requirejs for var o in umdf umdo; umd// -- Add your module definitions here ---------------- // ----------------------------------------------------umdnlength && ;}this 'function' == typeof define && define || void 0 'function' == typeof requirejs && requirejs || void 0 {};