javascript - ES6 async modules using multiple baseurls -
the es6 module system seems proper fit unifying commonjs / amd syntaxes. requirejs/amd-user i'd convert es6 modules (using babel.js now).
there seems 1 problem though; reading through docs , tutorials, there doesn't seem possible load module packages dependendent on more 1 baseurl. using requirejs solvable using context
field:
// async dependencies loaded http://path/to/domain var contextedrequire1 = require.config({ baseurl: 'http://path/to/domain/js', context: 'maincontext' }); // async dependencies located on http://path/to/otherdomain var contextrequire2 = require.config({ baseurl: 'http://path/to/otherdomain/js', context: 'plugincontext' }); contextedrequire1(['main.js'], function(main){ // loaded using http://path/to/domain/js/main.js contextedrequire2(['plugin-lazyloading-deps.js'], function(plugin){ plugin.init(); }); });
in main.js
define(['main-deps'], function(maindeps){ // loaded using http://path/to/domain/js/main-deps.js })
in plugin-lazyloading-deps.js
define(['require'], function(require){ // loaded using http://path/to/otherdomain/js/plugin-lazyloading-deps.js if(modernizr.touch) { require(['hammer'], function(){ // loaded using http://path/to/otherdomain/js/hammer.js hammer.init(); }) } })
in es6 async module imports isn't possible, since system
singleton
system.baseurl = "http://path/to/domain/js"; system.import("main").then(function(main){ // loaded using http://path/to/domain/js/main.js // potentially break when main.js tries load hammer.js http://path/to/domain/js system.baseurl = "http://path/to/otherdomain/js"; system.import("plugin-lazyloading-deps").then(function(){ /** code **/ }); });
my question is: there in docs i've missed (possible subclass system able config several baseurls), or in works future module extensions?
at least current version of systemjs, can provide wildcard paths. https://github.com/systemjs/systemjs/wiki/configuration-options#paths-unstable
i haven't used myself, case, seems you'd do
system.baseurl = 'http://path/to/domain/js'; system.paths['plugin-*'] = 'http://path/to/otherdomain/js/plugin-*';
Comments
Post a Comment