SlideShare ist ein Scribd-Unternehmen logo
1 von 23
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

Weitere ähnliche Inhalte

Was ist angesagt?

Asynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVM
Asynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVMAsynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVM
Asynchronous Module Definition (AMD) used for Dependency Injection (DI) and MVVMHugh Anderson
 
Workshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewWorkshop Intro: FrontEnd General Overview
Workshop Intro: FrontEnd General OverviewVisual Engineering
 
Requirejs
RequirejsRequirejs
Requirejssioked
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Workshop 4: NodeJS. Express Framework & MongoDB.
Workshop 4: NodeJS. Express Framework & MongoDB.Visual Engineering
 
Once upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side renderingOnce upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side renderingAndrea Giannantonio
 
Front-end build tools - Webpack
Front-end build tools - WebpackFront-end build tools - Webpack
Front-end build tools - WebpackRazvan Rosu
 
Testing nodejs apps
Testing nodejs appsTesting nodejs apps
Testing nodejs appsfelipefsilva
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express jsAhmed Assaf
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JSCakra Danu Sedayu
 
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложенияCodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложения
CodeFest 2014. Пухальский И. — Отзывчивые кроссплатформенные веб-приложенияCodeFest
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications Juliana Lucena
 
Backbone.js
Backbone.jsBackbone.js
Backbone.jsVO Tho
 
Modularize JavaScript with RequireJS
Modularize JavaScript with RequireJSModularize JavaScript with RequireJS
Modularize JavaScript with RequireJSMinh Hoang
 

Was ist angesagt? (20)

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

Andere mochten auch

EcoSense International, Inc. VaultOx
EcoSense International, Inc. VaultOxEcoSense International, Inc. VaultOx
EcoSense International, Inc. VaultOxEcoSenseINT
 
Caroline Miller Visual Imagination Project
Caroline Miller Visual Imagination ProjectCaroline Miller Visual Imagination Project
Caroline Miller Visual Imagination ProjectCaroline Miller
 
Engineering eCommerce systems for Scale
Engineering eCommerce systems for ScaleEngineering eCommerce systems for Scale
Engineering eCommerce systems for Scalevivekv
 
QOSMO by Diverge Design (Portugal)
QOSMO by Diverge Design (Portugal)QOSMO by Diverge Design (Portugal)
QOSMO by Diverge Design (Portugal)Jose dos Santos
 
Educción médica en un mundo globalizado
Educción médica en un mundo globalizadoEducción médica en un mundo globalizado
Educción médica en un mundo globalizadoEBAUTISTA
 
Reported Speech
Reported SpeechReported Speech
Reported Speechmsitgeba
 
TASK PRESENTATION
TASK PRESENTATIONTASK PRESENTATION
TASK PRESENTATIONmsitgeba
 
Memoria y aprendizaje
Memoria y aprendizajeMemoria y aprendizaje
Memoria y aprendizajeEBAUTISTA
 
Auxiliaries Ppt
Auxiliaries PptAuxiliaries Ppt
Auxiliaries Pptmsitgeba
 

Andere mochten auch (16)

Jetairfly Magazine 08
Jetairfly Magazine 08Jetairfly Magazine 08
Jetairfly Magazine 08
 
EcoSense International, Inc. VaultOx
EcoSense International, Inc. VaultOxEcoSense International, Inc. VaultOx
EcoSense International, Inc. VaultOx
 
Grece(Music)
Grece(Music)Grece(Music)
Grece(Music)
 
Caroline Miller Visual Imagination Project
Caroline Miller Visual Imagination ProjectCaroline Miller Visual Imagination Project
Caroline Miller Visual Imagination Project
 
My Routine
My RoutineMy Routine
My Routine
 
Engineering eCommerce systems for Scale
Engineering eCommerce systems for ScaleEngineering eCommerce systems for Scale
Engineering eCommerce systems for Scale
 
Sonido
SonidoSonido
Sonido
 
QOSMO by Diverge Design (Portugal)
QOSMO by Diverge Design (Portugal)QOSMO by Diverge Design (Portugal)
QOSMO by Diverge Design (Portugal)
 
Educción médica en un mundo globalizado
Educción médica en un mundo globalizadoEducción médica en un mundo globalizado
Educción médica en un mundo globalizado
 
Reported Speech
Reported SpeechReported Speech
Reported Speech
 
TASK PRESENTATION
TASK PRESENTATIONTASK PRESENTATION
TASK PRESENTATION
 
Memoria y aprendizaje
Memoria y aprendizajeMemoria y aprendizaje
Memoria y aprendizaje
 
Auxiliaries Ppt
Auxiliaries PptAuxiliaries Ppt
Auxiliaries Ppt
 
Plot And Plot Line
Plot And Plot LinePlot And Plot Line
Plot And Plot Line
 
El agua en puerto rico
El agua en puerto ricoEl agua en puerto rico
El agua en puerto rico
 
2 habilidades la_comunicacion
2 habilidades la_comunicacion2 habilidades la_comunicacion
2 habilidades la_comunicacion
 

Ähnlich wie uRequire@greecejs: An introduction to http://uRequire.org

Packing for the Web with Webpack
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with WebpackThiago Temple
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done RightMariusz Nowak
 
Modules and EmbedJS
Modules and EmbedJSModules and EmbedJS
Modules and EmbedJSJens Arps
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS MeetupLINAGORA
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundlerAndrea Giannantonio
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 
Voorhoede - Front-end architecture
Voorhoede - Front-end architectureVoorhoede - Front-end architecture
Voorhoede - Front-end architectureJasper Moelker
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan Cuprak
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascriptaglemann
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular applicationmirrec
 
Let's run JavaScript Everywhere
Let's run JavaScript EverywhereLet's run JavaScript Everywhere
Let's run JavaScript EverywhereTom Croucher
 
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ... Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...Mikko Ohtamaa
 
JS & NodeJS - An Introduction
JS & NodeJS - An IntroductionJS & NodeJS - An Introduction
JS & NodeJS - An IntroductionNirvanic Labs
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsRichard Rodger
 

Ähnlich wie uRequire@greecejs: An introduction to http://uRequire.org (20)

Packing for the Web with Webpack
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with Webpack
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
Modules and EmbedJS
Modules and EmbedJSModules and EmbedJS
Modules and EmbedJS
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS Meetup
 
JavaScript Module Loaders
JavaScript Module LoadersJavaScript Module Loaders
JavaScript Module Loaders
 
IOC + Javascript
IOC + JavascriptIOC + Javascript
IOC + Javascript
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 
A nodejs application
A nodejs applicationA nodejs application
A nodejs application
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Voorhoede - Front-end architecture
Voorhoede - Front-end architectureVoorhoede - Front-end architecture
Voorhoede - Front-end architecture
 
Node azure
Node azureNode azure
Node azure
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Let's run JavaScript Everywhere
Let's run JavaScript EverywhereLet's run JavaScript Everywhere
Let's run JavaScript Everywhere
 
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ... Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 
JS & NodeJS - An Introduction
JS & NodeJS - An IntroductionJS & NodeJS - An Introduction
JS & NodeJS - An Introduction
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
 

Kürzlich hochgeladen

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 

Kürzlich hochgeladen (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

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