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

Support for environments without window object (either as RequireJS/AMD, or global polyfill) #14

Closed
christopherliu opened this issue Feb 26, 2014 · 5 comments

Comments

@christopherliu
Copy link

The current polyfill works in browsers and (I assume) node, but not in evaluation environments without the window object.

(One module already uses var browserGlobal, so I'll see if I can extend that support in the rest of es6.)

@christopherliu
Copy link
Author

On further inspection, it looks like support in environments that use AMD is almost automatic; you'd have to take out the wrapping from vendor/loader.js. Then you'd have just a set of AMD modules, and you could do:

var Promise = require('promise/promise').Promise;

almost the same as the Node version. The only difference would be that you would have to define the locations of promise/*.

For the moment I'm going to hack around this by removing the vendor/loader.js and requireModule('promise/polyfill').polyfill(); by hand, but this is something a new Grunt task could probably do.

@simonpai
Copy link

simonpai commented Mar 3, 2014

Unfortunately even after stripping loader.js & the last line, what remains is not valid AMD syntax. The build task releases a *.amd.js file but it suffers the same issue.

@christopherliu
Copy link
Author

Interesting. In case it's helpful, I got it to work through the following:

  1. Removing the loader at the top and the requireModule('promise/polyfill').polyfill(); section at the end.

  2. In my RequireJS config, aliasing every Promise module to the same file, as so:

    'promise/promise': 'polyfills/promise-0.1.1-AMD',
    'promise/reject': 'polyfills/promise-0.1.1-AMD',
    'promise/race': 'polyfills/promise-0.1.1-AMD',
    'promise/utils': 'polyfills/promise-0.1.1-AMD',
    'promise/resolve': 'polyfills/promise-0.1.1-AMD',
    

I'm not sure that RequireJS is really ok with keeping multiple modules in the same file, but it is functional as far as my use cases have gone.

@msimulcik
Copy link

For multiple modules in the same file you can use bundles since RequireJS 2.1.10. In my RequireJS config it looks like this:

bundles: {
    'lib/es6-promise': [
        'promise/promise',
        'promise/reject',
        'promise/race',
        'promise/utils',
        'promise/resolve'
    ]
}

@stefanpenner stefanpenner mentioned this issue Aug 27, 2014
4 tasks
@stefanpenner
Copy link
Owner

should be fixed on master

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

No branches or pull requests

4 participants