Created
February 11, 2011 22:21
-
-
Save kara-ryli/823165 to your computer and use it in GitHub Desktop.
The many ways to manage dependencies in YUI3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add modules globally | |
(function () { | |
var cfg = window.YUI_config || {}; | |
cfg.modules = cfg.modules || {}; | |
// Add external dependencies | |
cfg.modules.externalDependency = { | |
fullpath: '/path/to/script.js', | |
requires: ['node', 'event'] | |
}; | |
// Add CSS dependencies | |
cfg.modules.cssDependency = { | |
fullpath: '/path/to/styles.css', | |
type: 'css' | |
}; | |
// Set up your own rollup | |
cfg.groups = cfg.groups || {}; | |
cfg.groups.myNameSpace = { | |
combine: true, // or false | |
comboBase: 'http://www.mysite.com/combo.php', | |
base: 'http://www.mysite.com/scripts/', | |
modules: { | |
module1: { path: 'module1.js'}, | |
css1: { path: 'css1.css'}, | |
module2: { path: 'module2.js', requires: ['module1', 'css1']} | |
} | |
}; | |
window.YUI_config = cfg; | |
}()); | |
YUI().use('externalDependency', 'cssDependency', 'module2', function (Y) { | |
// Your application code | |
}); | |
// Add modules at the sandbox level | |
YUI({ | |
modules: { | |
sandboxOnly: { fullpath: '/path/to/script.js' } | |
} | |
}).use(function (Y) { | |
// Your application code | |
}); | |
// Add modules at runtime | |
YUI().use(function (Y) { | |
YUI_config.modules.runtimeModule = { | |
fullpath: '/path/to/script', requires: ['node'] | |
}; | |
Y.applyConfig(YUI_config); | |
Y.use('runtimeModule', function (Y2) { // Y2 === Y | |
// Your application code | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment