-
Couldn't load subscription status.
- Fork 25
Allows to configure babel options via ember-cli-build #42
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| module.exports = { | ||
| root: true, | ||
| parser: 'babel-eslint', | ||
| parserOptions: { | ||
| ecmaFeatures: { | ||
| jsx: true, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| const VersionChecker = require('ember-cli-version-checker'); | ||
|
|
||
| function requireTransform(transformName) { | ||
| return require.resolve(transformName); | ||
| } | ||
|
|
||
| function hasPlugin(plugins, name) { | ||
| for (const maybePlugin of plugins) { | ||
| const plugin = Array.isArray(maybePlugin) ? maybePlugin[0] : maybePlugin; | ||
| const pluginName = typeof plugin === 'string' ? plugin : plugin.name; | ||
|
|
||
| if (pluginName === name) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| module.exports = function configureJsxTransform(parent) { | ||
| const options = (parent.options = parent.options || {}); | ||
|
|
||
| const checker = new VersionChecker(parent).for('ember-cli-babel', 'npm'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually utilising ember-cli-babel from the Ember App, which might be problematic if the app is using older Ember that uses babel 5. I would suggest to hook up babel ourselves so that we control how to compile JSX files ourselves. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was what I had in mind - ie use Babel from the app. Are you thinking that we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am actually thinking to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm... we could add another condition to lib to check if they're using babel5. Is there any difference between babel5 & babel6? It seems to come down to wether or not we're using the app's babel. I would prefer to use app's babel so babel features that are available in React and Ember are consistent. It would be pretty annoying to start using a feature in React then realize that it's not available in the Ember app and vice versa. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Babel 6 is incompatible with Babel 5, at least from the configuration. Also Babel 6 removed "require interop" that caused lots of application to have a hard to upgrading last time. I agree separating Babel config is troublesome but I think there are situations that we want to transpile React files differently with Ember files. Not sure if I am worrying too much :P @alexgb any input? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I think I'm getting it now. If I understand correctly, you're saying that when using I'm trying to avoid adding too much complexity to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes
This is where this PR started. If you look at the start of this PR, the first commit is da25380 which makes it possible to configure broccoli-react.
I suggested to remove const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const plugins = [
'transform-decorators-legacy',
'transform-object-rest-spread',
'transform-class-properties'
];
module.exports = function(defaults) {
let app = new EmberApp(defaults, {
babel: {
plugins
},
'ember-cli-react': {
babelOptions: {
plugins
},
},
});
return app.toTree();
};If we're ok with this, then I can just revert the changes and that I made in last few commits and push the original PR. Let me know what you think we should do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. Thanks for walking me through your thinking. So the main decision is between using the host app's babel to process JSX or an isolated
I think I'm coming around to using the host app's babel, but don't feel strongly. If we go this route I think it would be wise for us to add a peer dependency on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
👍
Are you sure it's using babel 5? The fact that it doesn't change babel dependency suggests to me that it's using whatever is installed before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I think you're right, which concerns me because we do test and indicate support for Ember versions down to 1.13 and it's unfortunate that ember-try just exercises ember and ember-data versions, but not the full set of ember-cli dependencies for a particular release. So yes, would be good to test babel5 compatibility, but not sure how to test that end to end. |
||
|
|
||
| options.babel = options.babel || {}; | ||
| options.babel.plugins = options.babel.plugins || []; | ||
|
|
||
| if (checker.satisfies('^6.0.0-beta.1')) { | ||
| if (!hasPlugin(options.babel.plugins, 'babel-plugin-transform-react-jsx')) { | ||
| options.babel.plugins.push( | ||
| requireTransform('babel-plugin-transform-react-jsx') | ||
| ); | ||
| } | ||
| } else if (checker.gte('7.0.0')) { | ||
| if ( | ||
| !hasPlugin(options.babel.plugins, '@babel/plugin-transform-react-jsx') | ||
| ) { | ||
| options.babel.plugins.push( | ||
| requireTransform('@babel/plugin-transform-react-jsx') | ||
| ); | ||
| } | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import React from 'react'; | ||
|
|
||
| class State { | ||
| message = 'supports class properties'; | ||
| } | ||
|
|
||
| export default function BabelFeatures() { | ||
| let attrs = { 'data-test': 'allows-object-spread' }; | ||
| let s = new State(); | ||
| return <div {...attrs}>{s.message}</div>; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we should be able to continue using
preprocessTreehere. Instead of using broccoli-react we do babel transpile and feed into funnel here directly.