ef4 / ember-browserify

ember-cli addon for easily loading CommonJS packages from npm via browserify.
MIT License
172 stars 28 forks source link

Transforming node_modules packages #60

Closed MattNguyen closed 8 years ago

MattNguyen commented 8 years ago

My issue specifically relates to transpiling node_modules packages with babelify.

Currently browserify does not transform node_modules packages by default.

https://github.com/babel/babelify/issues/38, https://github.com/babel/babelify/issues/44, and https://github.com/babel/babelify/issues/53 suggest adding the following to each node_modules package.json:

{
  "browserify": {
    "transform": ["babelify"]
  },
}

Unless I'm mistaken, this doesn't appear to work with ember-browserify and simply adding that to config/environment.js does not work either. Regardless, it seems unrealistic to have to add the aforementioned option to each third party package.

Does anyone have any suggestions to resolve this?

Thanks in advance!

asakusuma commented 8 years ago

Standard protocol for npm modules is to expose an ES5 CJS module in main. Thus, the expectation is that the dependency should not need to be babelified, which is why it's expected that a module should have to manually declare that it needs to be babelified if needed.

So my recommendation is that any dependencies expose ES5 to begin with. If that's not acceptable, can you create an example repo that demonstrates how the babelify plugin doesn't work with ember-browserify?

Also, what specific 3rd party packages are ES6 and require being babelified?

MattNguyen commented 8 years ago

Thanks for your response.

I made a test app here:

https://github.com/MattNguyen/babel-browserify

The test repo uses jsonwebtoken, which uses jws. jws uses es6, for example, here.

asakusuma commented 8 years ago

Sorry I was on vacation and am currently sick. Will try to get to this later this week.

asakusuma commented 8 years ago

@MattNguyen once I fixed the jQuery version problem, the test app seems to work for me. I get a token like: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiL..."

MattNguyen commented 8 years ago

@asakusuma - sorry for the delay and thanks for your response.

What was the jQuery version problem?

Also, did you check on a browser that doesn't support es6? When I test the build against IE 10, it fails. You can verify this by grepping for const in dist/vendor.js.

asakusuma commented 8 years ago

Issue was that version of jQuery specified conflicted with what was required by other modules.

I ran it on chrome, so I'll look at the code next time when I get a chance.

stefanpenner commented 8 years ago

Issue was that version of jQuery specified conflicted with what was required by other modules.

^, seems like not an issue with this project. Will reopen if i am not correct.