-
Notifications
You must be signed in to change notification settings - Fork 109
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
Apply Babel transpilation #41
Comments
I'd also like this feature. Or an example of how to set the webpack options to enable transpilation (with the same settings as the main app) |
Transpiling everything always would be safe, but it would potentially slow down builds a lot, and I strongly suspect that for most packages it would be a waste. It would be nice if there was more agreement about what kind of code to put into NPM packages, or at least some metadata in package.json that would give us hints about it. I think the most popular choice is still to transpile before publishing. But clearly some are going to start wanting to ship ES latest features.
I think we can implement this as a list of packages that you're opting in to transpiling (with the main app's settings). Each addon can add to the list. @Turbo87 did you find an example of a package you tried to auto-import that needs babel in order to work in your target browser set? |
I'd like to use https://www.npmjs.com/package/pdfjs, but it doesn't work in IE 11, because it's not being transpiled. |
I tend to disagree. Even using let/const is a problem and that is done quite a lot in Node.js packages these days.
we could look at the
true, but with
I like that idea, although I'd go with an opt-out approach. Most people likely don't test with IE11 and will only find out when they push to prod that their app is no longer working. I think correctness first, before speed, is the right way to go here, with an option for skipping transpilation if you know that the dep is bundled in a compatible way, or if you only support evergreen browsers.
I haven't done the full analysis yet (IE11 debugging is great...), but I suspect what broke it for us is https://github.com/sindresorhus/p-retry/ due to the ES6 class being used. |
Hmm, perhaps you are right. It sounds like we will need to be somewhat flexible in the config for this. I can certainly make both opt-in and opt-out work. |
We are running into issues with this right now as well. Is there a workaround right now? Maybe a branch we can point at? Maybe a way to use this customizing behavior |
As a workaround, it should be possible to apply babel via the webpack config. Something like module: {
rules: [
{ test: /\.js$/, loader: "babel-loader" }
]
} You may want to experiment with a pattern for |
I'm curious to see if there's an easy way to share the babel config from the rest of the consuming Ember app with |
It's not too hard and ember-auto-import already does it, see https://github.com/ef4/ember-auto-import/blob/ec307965ebbce248b27fb611ee0cd309056452af/ts/package.ts#L44 |
I was trying something similar from an app's const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
let app = new EmberApp(defaults, {
// Add options here
babel: {
plugins: [
require('ember-auto-import/babel-plugin')
]
}
});
app.options.autoImport = {
webpack: {
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: app.options.babel
}
}
]
}
}
}
return app.toTree();
}; Assuming the the |
In my case, there is this module which breaks IE11:
Will update here if I find why this module gets in my way and nobody else's... |
My problem was due to ember-cli-plotly which was pulling in both Back to normal after removing it. I don't know how I should feel. |
Does this change if it's an addon using ember-auto-import? My addon uses ember-auto-import, but after adding this to my addon's index.js file my consuming application doesn't build. I get the following error:
|
If the loader is a dependency of your addon, you'll need to resolve it from your addon. One way is: // added to the webpack config
resolveLoader: {
alias: {
'babel-loader': require.resolve('babel-loader')
}
} But PLEASE DON'T DO THIS. It's extremely disruptive behavior if adding your addon to a project causes every piece of third party javascript in the entire app to suddenly start going through babel. And this leaves no way for anybody else (either the app or another addon) to change anything about the babel config. Instead, you need to be careful to not mess with other people's things:
Here is one attempt, but test it:
|
This seems to run all dependencies through Babel. No guarantees on preventing extraneous transpiling or clobbering others' const { lstatSync, readdirSync } = require('fs');
const { join } = require('path');
//...
autoImport: {
webpack: {
module: {
rules: [
{
test: /\.m?js$/,
use: {
loader: require.resolve('babel-loader'),
options: {
presets: [['@babel/preset-env', { targets: require('./config/targets') }]],
},
},
include: readdirSync('node_modules')
.map((name) => join(__dirname, 'node_modules', name))
.filter((source) => lstatSync(source).isDirectory()),
},
],
},
},
}, |
This is still definitely a feature that is important. My goal here is not to allow arbitrary babel configs, but to allow the appropriate subset of the app's babel config to apply also to imported dependencies. It's a "subset" because we may need to disable things like module transpilation that we want to leave up to webpack. The challenge here is that doing anything other than all-or-nothing isn't simple. You can't easily pick a single dependency and choose to transpile only it, because later if it refactors itself into several sub-dependencies, you would need to make sure those deeper dependencies also get transpiled. So really, choosing to transpile some package implies transpiling it and all its dependencies recursively. And when you do that, you realize you can get conflicting settings for deeper dependencies that are consumed via multiple paths through the dependency graph. I'm hesitant to just always transpile everything because I'm confident we will find packages that break when you transpile them. I personally hit two babel bugs in the last month. We need to give people a way to at least work around these situations. I see two alternatives. Alternative 1 would need:
Alternative 2 would start from the assumption that we transpile everything, and only have Lastly, babel-loader doesn't make it very easy to be selective on a per-package basis (it's entirely file oriented), but I already have code in embroider that solves that problem, so I'm not worried about that aspect. |
I'm pretty sure that this is the case. Since we use latest Chrome for testing by default those transpilation issues won't show up unless you setup something with Browserstack and explicitly test in IE11. |
@kevincolten's solution seems to have worked for me, thank you for that! Others will need to |
Yeah, I'm seeing @kevincolten clobber something, but I'm not sure why: Perhaps it's transpiling something wrong. @ef4 is right, this shouldn't be transpiling everything - but is there a way to easily identify what packages aren't being transpiled? I can't comb through the |
I'm ready to settle on "Alternative 2" from my comment above. We should implement that. If somebody wants to implement, it's easier to see how it would work by looking at embroider (because embroider already has a We can use the |
Equivalent issue in embroider is embroider-build/embroider#3 We want the same behavior in both. |
Fixed in #225 |
It appears that currently the
config/targets.js
file is not considered and the code is bundled as is. It would probably be good if the resulting trees would be passed through Babel before being included in the final build.The text was updated successfully, but these errors were encountered: