-
Notifications
You must be signed in to change notification settings - Fork 25k
Add transform-react-jsx-source to react-native preset #6351
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
Conversation
|
By analyzing the blame information on this pull request, we identified @skevy to be a potential reviewer. |
|
babel-preset-react-native is likely the right place -- we consolidate all babel plugins in this preset so that people can use the react-native preset in custom .babelrc files and automatically get the same configuration as a plain RN project. Making the plugin run only in dev is trickier though.... perhaps we need to create 2 presets: Another option is to have the packager explicitly load this plugin (ex: react-native/packager/transformer.js Line 82 in e6cb02d
|
|
There is a env option for the babelrc file, maybe it could work here. https://babeljs.io/docs/usage/babelrc/#env-option Otherwise we could set an environment variable (or something else if there is a better way to pass data) in the packager before running the transforms and check it in the preset. |
|
Fantastic -- let's set |
|
Lmk how you want to proceed, I don't have strong opinions regarding babel configuration, but I can't wait to show you a demo of what this thing enables us to do! |
|
I want to see this demo! |
|
You can try something like this: {
plugins: resolvePlugins([
...
]),
env: {
development: {
plugins: resolvePlugins(['babel-plugin-transform-react-jsx-source']),
},
},
}I'm not sure the env config only works in .babelrc files. Then we should probably set the |
|
Maybe @kittens can chip in here see if we are doing this right :) |
|
@frantic could you try using Babel's env option that @janicduplessis linked to, and see if you can make it so that the plugin runs only in dev mode? |
|
Curious, what if someone is relying on a |
|
Yeah using the |
|
@frantic do you have any updates for this pull request? It's been a while so we wanted to check in and see if you've looked at the requested changes. |
fbbc312 to
fbe8a31
Compare
|
@frantic updated the pull request. |
1 similar comment
|
@frantic updated the pull request. |
|
@martinbigio would you mind taking a look at this pull request? It's been a while since the last commit was reviewed. |
|
@kittens does the code with |
|
@frantic updated the pull request. |
|
@skevy would you mind taking a look at this pull request? It's been a while since the last commit was reviewed. |
package.json
Outdated
| "babel-plugin-external-helpers": "^6.5.0", | ||
| "babel-polyfill": "^6.6.1", | ||
| "babel-preset-react-native": "^1.7.0", | ||
| "babel-preset-react-native": "frantic/babel-preset-react-native", |
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.
Remove this, please. We will have to update this seperately (i.e. after publishing to npm)
Summary: Depends on #6351 Now you can open file directly from Elements Inspector! Credit for the original implementation goes to jaredly  **Test plan** Made sure it doesn't crash the app with or without #6351 (i.e. can be merged safely before #6351 gets in). Closes #7005 Differential Revision: D3313714 Pulled By: frantic fbshipit-source-id: 3b80abd3e81a0db5ca5136e2d2c94c775fa04f3a
Summary: Putting this up as request for comments. The PR adds [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) to the list of plugins that come by default with the `react-native` preset. It will enable the use of a bunch of really cool tooling around JSX, however those are generally useful only in development mode. Is changing `react-native` preset the right thing to do in this case? Is there a way to enable this transform only in DEV? Should I add this somewhere else? Closes facebook#6351 Differential Revision: D3302906 Pulled By: frantic fbshipit-source-id: 012d3a4142168f9f90d30d1686115d4dc3996eb9
Summary: Depends on facebook#6351 Now you can open file directly from Elements Inspector! Credit for the original implementation goes to jaredly  **Test plan** Made sure it doesn't crash the app with or without facebook#6351 (i.e. can be merged safely before facebook#6351 gets in). Closes facebook#7005 Differential Revision: D3313714 Pulled By: frantic fbshipit-source-id: 3b80abd3e81a0db5ca5136e2d2c94c775fa04f3a
Summary: Putting this up as request for comments. The PR adds [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) to the list of plugins that come by default with the `react-native` preset. It will enable the use of a bunch of really cool tooling around JSX, however those are generally useful only in development mode. Is changing `react-native` preset the right thing to do in this case? Is there a way to enable this transform only in DEV? Should I add this somewhere else? Closes facebook#6351 Differential Revision: D3302906 Pulled By: frantic fbshipit-source-id: 012d3a4142168f9f90d30d1686115d4dc3996eb9
|
Notice that highjacking the |
|
@oliviertassinari What do you mean by to make a React Dom and React Native works under the same directory? |
|
@satya164 Well, I have two implementations of the same components for two platforms inside the same folder. Basically, To make this work, I have a single
|
To take advantage of this, use the [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) babel plugin. The `_source` property was added to react [last year](facebook/react@009b7c8) and can be used by development tools to track the source file & line of react elements. React Native is also [taking advantage of it](facebook/react-native#6351). Test Plan: - install the [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) babel plugin - open the react devtools to an element that was created in your app (can't have been created by a library you're using, because those are probably pre-transpiled & ignored by babel)
To take advantage of this, use the [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) babel plugin. The `_source` property was added to react [last year](facebook/react@009b7c8) and can be used by development tools to track the source file & line of react elements. React Native is also [taking advantage of it](facebook/react-native#6351). Test Plan: - install the [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) babel plugin - open the react devtools to an element that was created in your app (can't have been created by a library you're using, because those are probably pre-transpiled & ignored by babel)
* Handle & render the _source property To take advantage of this, use the [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) babel plugin. The `_source` property was added to react [last year](facebook/react@009b7c8) and can be used by development tools to track the source file & line of react elements. React Native is also [taking advantage of it](facebook/react-native#6351). Test Plan: - install the [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) babel plugin - open the react devtools to an element that was created in your app (can't have been created by a library you're using, because those are probably pre-transpiled & ignored by babel) * add readme line * fix type check * remove `shortFilePath`
Summary: Depends on facebook#6351 Now you can open file directly from Elements Inspector! Credit for the original implementation goes to jaredly  **Test plan** Made sure it doesn't crash the app with or without facebook#6351 (i.e. can be merged safely before facebook#6351 gets in). Closes facebook#7005 Differential Revision: D3313714 Pulled By: frantic fbshipit-source-id: 3b80abd3e81a0db5ca5136e2d2c94c775fa04f3a
Summary: Putting this up as request for comments. The PR adds [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) to the list of plugins that come by default with the `react-native` preset. It will enable the use of a bunch of really cool tooling around JSX, however those are generally useful only in development mode. Is changing `react-native` preset the right thing to do in this case? Is there a way to enable this transform only in DEV? Should I add this somewhere else? Closes facebook#6351 Differential Revision: D3302906 Pulled By: frantic fbshipit-source-id: 012d3a4142168f9f90d30d1686115d4dc3996eb9
Summary: Depends on facebook#6351 Now you can open file directly from Elements Inspector! Credit for the original implementation goes to jaredly  **Test plan** Made sure it doesn't crash the app with or without facebook#6351 (i.e. can be merged safely before facebook#6351 gets in). Closes facebook#7005 Differential Revision: D3313714 Pulled By: frantic fbshipit-source-id: 3b80abd3e81a0db5ca5136e2d2c94c775fa04f3a
Summary: Putting this up as request for comments. The PR adds [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) to the list of plugins that come by default with the `react-native` preset. It will enable the use of a bunch of really cool tooling around JSX, however those are generally useful only in development mode. Is changing `react-native` preset the right thing to do in this case? Is there a way to enable this transform only in DEV? Should I add this somewhere else? Closes facebook#6351 Differential Revision: D3302906 Pulled By: frantic fbshipit-source-id: 012d3a4142168f9f90d30d1686115d4dc3996eb9
Summary: Putting this up as request for comments. The PR adds [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) to the list of plugins that come by default with the `react-native` preset. It will enable the use of a bunch of really cool tooling around JSX, however those are generally useful only in development mode. Is changing `react-native` preset the right thing to do in this case? Is there a way to enable this transform only in DEV? Should I add this somewhere else? Closes facebook/react-native#6351 Differential Revision: D3302906 Pulled By: frantic fbshipit-source-id: 012d3a4142168f9f90d30d1686115d4dc3996eb9
|
Can someone explain why https://github.com/facebook/react-native/pull/6351/files#diff-4676ea0b3c55c65c3929aa993144f07fR104 is needed? |
|
@okonet that’s for third-party code relying on it. |
|
I would be happy to remove it, but I am not sure how many user setups that would affect |
|
Can we rewrite the check so it won't overwrite the passed env but only check if it's development? |
|
Maybe we can not overwrite passed-in envs. Please be aware that neither |
|
The goal of this was to pass the packager dev env to babel so if you pass &dev=true it will run plugins in the env.development config. |
|
If it causes issues there are probably other ways to do it. |
|
@janicduplessis yeah, the fact it overwrites and ignores I could do a PR with a potential fix but I don't have any experience with RN yet. |
|
It seems this must be fixed in 0.46: https://github.com/okonet/react-native/blob/0.46-stable/babel-preset/configs/main.js |
Summary: **Summary** Allows custom non-dev `BABEL_ENV`s besides `'production'`. With respect to facebook/react-native#6351 (comment). **Test plan** This change will break non-dev builds for people who for any reason has custom `BABEL_ENV` set but expects it to behave like `'production`' (current behavior). Though it can be easily fixed either by renaming their `env` from `production` to the value of custom `BABEL_ENV`, or by changing `BABEL_ENV` from custom to `'production'`. Other than this unusual case, nothing should change. Pull Request resolved: #364 Differential Revision: D14206886 Pulled By: cpojer fbshipit-source-id: 3e4ef2b2beb4ce94335f72cc974d35312f847a9f

Putting this up as request for comments.
The PR adds transform-react-jsx-source to the list of plugins that come by default with the
react-nativepreset. It will enable the use of a bunch of really cool tooling around JSX, however those are generally useful only in development mode. Is changingreact-nativepreset the right thing to do in this case? Is there a way to enable this transform only in DEV? Should I add this somewhere else?