Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add System.register as a format target #11

Open
matthewp opened this issue Oct 17, 2014 · 2 comments
Open

Add System.register as a format target #11

matthewp opened this issue Oct 17, 2014 · 2 comments

Comments

@matthewp
Copy link
Member

For production builds System.register is a better option long-term. I keep running into weird cases with having a bunch of named AMD defines in a single file, I don't feel confident that it's always going to be viable to go that way.

@justinbmeyer
Copy link
Contributor

@matthewp I would prefer to write to AMD because its a format that's supported by other loaders. It's not "owned" by SystemJS and designed for "jspm".

But, for globals, this is something we might need to do sooner than later. I was able to get a global to work by writing out something like:

System.register("slave", [], false, function(){
    var load = {source: "window.slave = {name: 'slave'};", name: "slave", metadata: {format: "global", exports: "slave", deps: []}};
    var exportName = load.metadata.exports;

    var loader = System;

    loader.get('@@global-helpers').prepareGlobal(load.name, load.metadata.deps);

    if (exportName)
      load.source += '\nthis["' + exportName + '"] = ' + exportName + ';';

    // disable AMD detection
    var define = loader.global.define;
    loader.global.define = undefined;

    // ensure no NodeJS environment detection
    loader.global.module = undefined;
    loader.global.exports = undefined;

    loader.__exec(load);

    loader.global.define = define;

    return loader.get('@@global-helpers').retrieveGlobal(load.name, exportName, load.metadata.init);
});

instead of:

System.define("slave","window.slave = {name: 'slave'};",{"metadata": {"format": "global"}});

cc @alexisabril

@matthewp
Copy link
Member Author

I got this to work for globals using the same technique in systemjs/builder. I see no reason why it has to be System.register though, this will work as a define as well. So I'm going to try this next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants