The JavaScript Universal Module &
Resource Converter
“Write modular JavaScript code once, run everywhere” is a reality.
uRequire.org
• Why Modularity
• JavaScript module systems
• uRequire primer
• A modules & dependencies builder
• Build config usage
uRequire.org
Why modularity
• Maintainable & reusable code
– Organize code in logical parts
– Clearly stated dependencies
– Reusability, Replace-ability, Testability etc
• Employ standards and trusted tools
– Unit Testing, Versioning, Regression Testing
• Have a dynamic code loading mechanism.
• End the damnation of
– Authoring “OneHuge.js” file
– .js file concatenation
uRequire.org
• Why Modularity
• JavaScript module systems & woes
• uRequire primer
• A modules & dependencies builder
• Build config usage
uRequire.org
CommonJS (nodejs)
var dep1 = require("../some/path/dep1"),
dep2 = require("../other/path/dep2"),
localDep = require("localDep");// ‘localDep’ in node_modules
// do stuff with dep1, dep2 & localDep
// `return` module value
module.exports = {my: "module"}
// or set properties on `exports`
exports.my = "module" // `exports` is a pre-given {}
uRequire.org
AMD (browser)
Asynchronous Module Definition
define([“../some/path/dep1”, “other/path/dep2”,“localDep”],
function(dep1, dep2, localDep) {
// do stuff with dep1, dep2, localDep
return {my:'module'}
}
);
uRequire.org
• Many woes on Module formats & incompatibilities
• Verbose syntax, boilerplate ceremony & intricacies
(especially AMD)
• execution environment (AMD only for Web,
CommonJs only for nodejs)
• capabilities, dependency/path resolutions, plugins,
semantics etc are a mess
• UMD is a semi-standard boilerplate, far from usable.
• U need a bridge to enjoy the richness of modules.
uRequire.org
Why do JavaScript developers hate
modules ?
Mixing AMD & CommonJs ?
define(['main/dep1', 'main/helpers/dep2'],
function(dep1, dep2) {
var dep3 = require('moredeps/dep3');
if (dep3(dep1) === 'wow'){
require(['./dep4'], function(dep4) {
// asynchronously do things with dep4
});
}
// do stuff with dep1, dep2, dep3
return {my:'module'}
}
);
uRequire.org
Too many woes
AMD: “require” needs to be in []
dependencies 1st (& fn params)
AMD: “moredeps/dep3” not
listed as [] dependency, halts
nodejs: ‘define’
is unknown (use
amdefine ?)
nodejs: async
‘require’ not working
nodejs: bundleRelative
paths not working
UMD: Universal Module Definition
// https://github.com/umdjs/umd/blob/master/returnExports.js
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('b'));
} else {
// Browser globals (root is window)
root.returnExports = factory(root.b);
}
}(this, function (b) {
// use b in some fashion.
// Just return a value to define the module export.
// This example returns {}, but can return a function as the exported value.
return {};
}));
uRequire.org
Not really a “Universal” one but …
… 10s of proposed module templates, for different scenarios.
Dependency path resolution:
• nodejs: relative to requiring file (fileRelative) only:
• AMD: relative to bundle (bundleRelative) also:
• Both are useful (at times). Can we use both ?
uRequire.org
AMD + CommonJS = neighbors from hell
var replace = require(“../../../string/replace");
• define(["utils/string/replace"], ...);
• Why Modularity
• JavaScript module systems & woes
• uRequire primer
• A modules & dependencies builder
• Build config usage
uRequire.org
uRequire primer
• Convert from any format to any other:
– from AMD and CommonJS (.js, .coffee, .iced, .coco, .ls)
– to AMD, CommonJS, UMD, Combined for nodejs-Web/AMD-
Web/Script
– Control conversion features (runtimeInfo, globalWindow etc)
• Forget the woes or Module formats incompatibilities
– Resolve paths, fill missing deps from [], inject ‘require’ etc
• Eliminate boilerplate & write modular Javascript code
once, run everywhere : Web/Script, Web/AMD, nodejs
• A Universal Module Format with the power, goodies &
standards from all.
• Convert to a single combined.js, that runs everywhere &
is super optimized uRequire.org
• Why Modularity
• JavaScript module systems & woes
• uRequire primer
• A modules & dependencies builder
• Build config usage
uRequire.org
A Modules & Dependencies aware builder.
• Exporting modules to global (like window.$)
with no boilerplate.
• Want noConflict(), baked in? Its a simple
declaration away.
• The same in a config:
• Export to bundle:
uRequire.org
// file `uberscore.js` - export it to root (`window`) as `_B`
({ urequire: { rootExports: '_B', noConflict: true }});
module.exports = {...}
dependencies: { exports: { root: { 'uberscore': '_B' }}}
dependencies: { exports: { bundle: { ‘lodash': '_' }}}
Manipulate module dependencies
• Replace deps with mocks or alternative versions:
• With a ResourceConverter callback:
uRequire.org
// underscore is dead, long live _
dependencies: { replace: { lodash: 'underscore'}}
function(m){
m.replaceDeps('models/PersonModel','mock/models/PersonModelMock');
}
Manipulate Module Code
Inject, replace or delete code fragments or AST nodes:
• Delete matching code of code skeleton
• Traverse matching nodes, replace or delete them
• Inject code before (or after) each module's body:
uRequire.org
function(m){ m.replaceCode('if (debug){}') }
function(m){ m.replaceCode('console.log()', function(nodeAST){}) }
function(m) { m.beforeBody = 'var VERSION = ‘1.0’;' }
Manipulate Module Code
Inject common or merged statements:
• beforeBody can be calculated per module
• Before main body at each module:
• Like above, but merge code on 'combined' template:
uRequire.org
bundle: commonCode: 'var expect = chai.expect;'
function(m) {
m.mergedCode = '"var p1 = myModule.p1, p2 = myModule.p2;"'
}
function(m) {
m.beforeBody = "var l = new _B.Logger('" + m.dstFilename + "');";
}
• Why Modularity
• JavaScript module systems & woes
• uRequire primer
• A modules & dependencies builder
• Build config usage
uRequire.org
uRequire config
uRequire.org
uberscore:
path: 'source'
dstPath: 'build'
filez: ['**/*', (f)-> f isnt 'badfile']
copy: [/./]
runtimeInfo: ['!**/*', 'Logger']
dependencies: exports:
bundle: 'lodash': '_'
root: 'uberscore': '_B'
resources: [
['+inject:VERSION', ['uberscore.js'],
(m)-> m.beforeBody = "var VERSION ='0.0.15';"]
]
template: banner: "// uBerscore v0.0.15"
read files from ‘source’
save to ‘build’
filter some filez
copy all other files
affect template selectively
inject ‘lodash’ in each module
export ‘uberscore’ as
`window._B` with noConflict()
inject ‘VERSION = ..’ before body
banner after template/optimize
Can be gruntjs, .coffee / .js nodejs module, .json, .yml & more
Deriving a config
uRequire.org
min:
derive: ['uberscore']
filez: ['!', /RegExpSpecs/]
template: 'combined'
dstPath: 'build/uberscore-min.js'
optimize: true
inherit deeply & modify
filter more filez
change template
optimize through Uglify2.
Can also pass an options {}
• Deeply inherit / extend all properties
change destination
filez: ['**/*', (f)-> f isnt 'badfile', '!', /RegExpSpecs/]
• Either overwriting or appending props:
Declarative template options
uRequire.org
globalWindow: false
runtimeInfo: ['Logger']
useStrict: true
injectExportsModule: ['circular/Dependency']
bare: true
allNodeRequires: ['/data/preCached']
noRootExports: true
scanAllow: false
window === global always
__isWeb, __isNode & __isAMD
inject 'use strict;‘
inject ‘exports’ & ‘module’
no enclosing function
& more…
• per module (minimatch of module path)
• whole bundle (true)
• Why Modularity
• JavaScript module systems & woes
• uRequire primer
• A modules & dependencies builder
• Build config usage
•Thank you
uRequire.org
uRequire.org

More Related Content

PDF
Requirejs
PDF
JavaScript Dependencies, Modules & Browserify
PDF
Browserify
PPSX
RequireJS
PDF
Lightning Talk: Making JS better with Browserify
PDF
Asynchronous Module Definition (AMD)
PPT
Managing JavaScript Dependencies With RequireJS
PDF
Workshop 16: EmberJS Parte I
Requirejs
JavaScript Dependencies, Modules & Browserify
Browserify
RequireJS
Lightning Talk: Making JS better with Browserify
Asynchronous Module Definition (AMD)
Managing JavaScript Dependencies With RequireJS
Workshop 16: EmberJS Parte I

What's hot (20)

PDF
The SPDY Protocol
PPTX
Asynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVM
PPTX
Workshop Intro: FrontEnd General Overview
KEY
Requirejs
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
PDF
Workshop 21: React Router
PDF
Once upon a time, there were css, js and server-side rendering
PPTX
Vue business first
PDF
Front-end build tools - Webpack
PPTX
Testing nodejs apps
PPTX
Module design pattern i.e. express js
PDF
Express node js
PPTX
Build RESTful API Using Express JS
PDF
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
PPT
Node.js Express Framework
PDF
PDF
Module, AMD, RequireJS
PDF
Ember.js - A JavaScript framework for creating ambitious web applications
PPTX
Backbone.js
PDF
Modularize JavaScript with RequireJS
The SPDY Protocol
Asynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVM
Workshop Intro: FrontEnd General Overview
Requirejs
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 21: React Router
Once upon a time, there were css, js and server-side rendering
Vue business first
Front-end build tools - Webpack
Testing nodejs apps
Module design pattern i.e. express js
Express node js
Build RESTful API Using Express JS
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
Node.js Express Framework
Module, AMD, RequireJS
Ember.js - A JavaScript framework for creating ambitious web applications
Backbone.js
Modularize JavaScript with RequireJS
Ad

Viewers also liked (16)

PDF
Jetairfly Magazine 08
PDF
EcoSense International, Inc. VaultOx
PPS
Grece(Music)
PPT
Caroline Miller Visual Imagination Project
PPT
PDF
Engineering eCommerce systems for Scale
PPT
PDF
QOSMO by Diverge Design (Portugal)
PPTX
Educción médica en un mundo globalizado
PPT
Reported Speech
PPT
TASK PRESENTATION
PPTX
Memoria y aprendizaje
PPT
Auxiliaries Ppt
PPT
Plot And Plot Line
PPTX
El agua en puerto rico
PDF
2 habilidades la_comunicacion
Jetairfly Magazine 08
EcoSense International, Inc. VaultOx
Grece(Music)
Caroline Miller Visual Imagination Project
Engineering eCommerce systems for Scale
QOSMO by Diverge Design (Portugal)
Educción médica en un mundo globalizado
Reported Speech
TASK PRESENTATION
Memoria y aprendizaje
Auxiliaries Ppt
Plot And Plot Line
El agua en puerto rico
2 habilidades la_comunicacion
Ad

Similar to uRequire@greecejs: An introduction to http://uRequire.org (20)

PPTX
Packing for the Web with Webpack
PDF
JavaScript Modules Done Right
KEY
Modules and EmbedJS
PDF
Advanced Node.JS Meetup
PPTX
JavaScript Module Loaders
PDF
IOC + Javascript
PPTX
node.js.pptx
KEY
A nodejs application
PDF
Webpack: your final module bundler
PPTX
Intro To Node.js
PPTX
Introduction to node.js GDD
PDF
Voorhoede - Front-end architecture
PDF
Node azure
PPTX
Preparing for java 9 modules upload
PPTX
Beyond DOMReady: Ultra High-Performance Javascript
PPTX
Rails Engine | Modular application
KEY
Let's run JavaScript Everywhere
KEY
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
PPTX
JS & NodeJS - An Introduction
KEY
Introducing the Seneca MVP framework for Node.js
Packing for the Web with Webpack
JavaScript Modules Done Right
Modules and EmbedJS
Advanced Node.JS Meetup
JavaScript Module Loaders
IOC + Javascript
node.js.pptx
A nodejs application
Webpack: your final module bundler
Intro To Node.js
Introduction to node.js GDD
Voorhoede - Front-end architecture
Node azure
Preparing for java 9 modules upload
Beyond DOMReady: Ultra High-Performance Javascript
Rails Engine | Modular application
Let's run JavaScript Everywhere
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
JS & NodeJS - An Introduction
Introducing the Seneca MVP framework for Node.js

Recently uploaded (20)

PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PPTX
Introduction to Windows Operating System
PPTX
Python is a high-level, interpreted programming language
PDF
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
PPTX
Airline CRS | Airline CRS Systems | CRS System
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PPTX
Cybersecurity: Protecting the Digital World
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PDF
Visual explanation of Dijkstra's Algorithm using Python
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
Microsoft Office 365 Crack Download Free
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PPTX
Download Adobe Photoshop Crack 2025 Free
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PPTX
Full-Stack Developer Courses That Actually Land You Jobs
BoxLang Dynamic AWS Lambda - Japan Edition
Introduction to Windows Operating System
Python is a high-level, interpreted programming language
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
Airline CRS | Airline CRS Systems | CRS System
CCleaner 6.39.11548 Crack 2025 License Key
Cybersecurity: Protecting the Digital World
iTop VPN Crack Latest Version Full Key 2025
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
How Tridens DevSecOps Ensures Compliance, Security, and Agility
DNT Brochure 2025 – ISV Solutions @ D365
Visual explanation of Dijkstra's Algorithm using Python
MCP Security Tutorial - Beginner to Advanced
Microsoft Office 365 Crack Download Free
Practical Indispensable Project Management Tips for Delivering Successful Exp...
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
Download Adobe Photoshop Crack 2025 Free
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
Full-Stack Developer Courses That Actually Land You Jobs

uRequire@greecejs: An introduction to http://uRequire.org

  • 1. The JavaScript Universal Module & Resource Converter “Write modular JavaScript code once, run everywhere” is a reality. uRequire.org
  • 2. • Why Modularity • JavaScript module systems • uRequire primer • A modules & dependencies builder • Build config usage uRequire.org
  • 3. Why modularity • Maintainable & reusable code – Organize code in logical parts – Clearly stated dependencies – Reusability, Replace-ability, Testability etc • Employ standards and trusted tools – Unit Testing, Versioning, Regression Testing • Have a dynamic code loading mechanism. • End the damnation of – Authoring “OneHuge.js” file – .js file concatenation uRequire.org
  • 4. • Why Modularity • JavaScript module systems & woes • uRequire primer • A modules & dependencies builder • Build config usage uRequire.org
  • 5. CommonJS (nodejs) var dep1 = require("../some/path/dep1"), dep2 = require("../other/path/dep2"), localDep = require("localDep");// ‘localDep’ in node_modules // do stuff with dep1, dep2 & localDep // `return` module value module.exports = {my: "module"} // or set properties on `exports` exports.my = "module" // `exports` is a pre-given {} uRequire.org
  • 6. AMD (browser) Asynchronous Module Definition define([“../some/path/dep1”, “other/path/dep2”,“localDep”], function(dep1, dep2, localDep) { // do stuff with dep1, dep2, localDep return {my:'module'} } ); uRequire.org
  • 7. • Many woes on Module formats & incompatibilities • Verbose syntax, boilerplate ceremony & intricacies (especially AMD) • execution environment (AMD only for Web, CommonJs only for nodejs) • capabilities, dependency/path resolutions, plugins, semantics etc are a mess • UMD is a semi-standard boilerplate, far from usable. • U need a bridge to enjoy the richness of modules. uRequire.org Why do JavaScript developers hate modules ?
  • 8. Mixing AMD & CommonJs ? define(['main/dep1', 'main/helpers/dep2'], function(dep1, dep2) { var dep3 = require('moredeps/dep3'); if (dep3(dep1) === 'wow'){ require(['./dep4'], function(dep4) { // asynchronously do things with dep4 }); } // do stuff with dep1, dep2, dep3 return {my:'module'} } ); uRequire.org Too many woes AMD: “require” needs to be in [] dependencies 1st (& fn params) AMD: “moredeps/dep3” not listed as [] dependency, halts nodejs: ‘define’ is unknown (use amdefine ?) nodejs: async ‘require’ not working nodejs: bundleRelative paths not working
  • 9. UMD: Universal Module Definition // https://github.com/umdjs/umd/blob/master/returnExports.js (function (root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['b'], factory); } else if (typeof exports === 'object') { // Node. Does not work with strict CommonJS, but // only CommonJS-like environments that support module.exports, like Node. module.exports = factory(require('b')); } else { // Browser globals (root is window) root.returnExports = factory(root.b); } }(this, function (b) { // use b in some fashion. // Just return a value to define the module export. // This example returns {}, but can return a function as the exported value. return {}; })); uRequire.org Not really a “Universal” one but … … 10s of proposed module templates, for different scenarios.
  • 10. Dependency path resolution: • nodejs: relative to requiring file (fileRelative) only: • AMD: relative to bundle (bundleRelative) also: • Both are useful (at times). Can we use both ? uRequire.org AMD + CommonJS = neighbors from hell var replace = require(“../../../string/replace"); • define(["utils/string/replace"], ...);
  • 11. • Why Modularity • JavaScript module systems & woes • uRequire primer • A modules & dependencies builder • Build config usage uRequire.org
  • 12. uRequire primer • Convert from any format to any other: – from AMD and CommonJS (.js, .coffee, .iced, .coco, .ls) – to AMD, CommonJS, UMD, Combined for nodejs-Web/AMD- Web/Script – Control conversion features (runtimeInfo, globalWindow etc) • Forget the woes or Module formats incompatibilities – Resolve paths, fill missing deps from [], inject ‘require’ etc • Eliminate boilerplate & write modular Javascript code once, run everywhere : Web/Script, Web/AMD, nodejs • A Universal Module Format with the power, goodies & standards from all. • Convert to a single combined.js, that runs everywhere & is super optimized uRequire.org
  • 13. • Why Modularity • JavaScript module systems & woes • uRequire primer • A modules & dependencies builder • Build config usage uRequire.org
  • 14. A Modules & Dependencies aware builder. • Exporting modules to global (like window.$) with no boilerplate. • Want noConflict(), baked in? Its a simple declaration away. • The same in a config: • Export to bundle: uRequire.org // file `uberscore.js` - export it to root (`window`) as `_B` ({ urequire: { rootExports: '_B', noConflict: true }}); module.exports = {...} dependencies: { exports: { root: { 'uberscore': '_B' }}} dependencies: { exports: { bundle: { ‘lodash': '_' }}}
  • 15. Manipulate module dependencies • Replace deps with mocks or alternative versions: • With a ResourceConverter callback: uRequire.org // underscore is dead, long live _ dependencies: { replace: { lodash: 'underscore'}} function(m){ m.replaceDeps('models/PersonModel','mock/models/PersonModelMock'); }
  • 16. Manipulate Module Code Inject, replace or delete code fragments or AST nodes: • Delete matching code of code skeleton • Traverse matching nodes, replace or delete them • Inject code before (or after) each module's body: uRequire.org function(m){ m.replaceCode('if (debug){}') } function(m){ m.replaceCode('console.log()', function(nodeAST){}) } function(m) { m.beforeBody = 'var VERSION = ‘1.0’;' }
  • 17. Manipulate Module Code Inject common or merged statements: • beforeBody can be calculated per module • Before main body at each module: • Like above, but merge code on 'combined' template: uRequire.org bundle: commonCode: 'var expect = chai.expect;' function(m) { m.mergedCode = '"var p1 = myModule.p1, p2 = myModule.p2;"' } function(m) { m.beforeBody = "var l = new _B.Logger('" + m.dstFilename + "');"; }
  • 18. • Why Modularity • JavaScript module systems & woes • uRequire primer • A modules & dependencies builder • Build config usage uRequire.org
  • 19. uRequire config uRequire.org uberscore: path: 'source' dstPath: 'build' filez: ['**/*', (f)-> f isnt 'badfile'] copy: [/./] runtimeInfo: ['!**/*', 'Logger'] dependencies: exports: bundle: 'lodash': '_' root: 'uberscore': '_B' resources: [ ['+inject:VERSION', ['uberscore.js'], (m)-> m.beforeBody = "var VERSION ='0.0.15';"] ] template: banner: "// uBerscore v0.0.15" read files from ‘source’ save to ‘build’ filter some filez copy all other files affect template selectively inject ‘lodash’ in each module export ‘uberscore’ as `window._B` with noConflict() inject ‘VERSION = ..’ before body banner after template/optimize Can be gruntjs, .coffee / .js nodejs module, .json, .yml & more
  • 20. Deriving a config uRequire.org min: derive: ['uberscore'] filez: ['!', /RegExpSpecs/] template: 'combined' dstPath: 'build/uberscore-min.js' optimize: true inherit deeply & modify filter more filez change template optimize through Uglify2. Can also pass an options {} • Deeply inherit / extend all properties change destination filez: ['**/*', (f)-> f isnt 'badfile', '!', /RegExpSpecs/] • Either overwriting or appending props:
  • 21. Declarative template options uRequire.org globalWindow: false runtimeInfo: ['Logger'] useStrict: true injectExportsModule: ['circular/Dependency'] bare: true allNodeRequires: ['/data/preCached'] noRootExports: true scanAllow: false window === global always __isWeb, __isNode & __isAMD inject 'use strict;‘ inject ‘exports’ & ‘module’ no enclosing function & more… • per module (minimatch of module path) • whole bundle (true)
  • 22. • Why Modularity • JavaScript module systems & woes • uRequire primer • A modules & dependencies builder • Build config usage •Thank you uRequire.org