-
Notifications
You must be signed in to change notification settings - Fork 518
Enable babel-plugin-transform-react-jsx-source in development for better warning messages #739
Comments
I don't currently have time to make a pull request for this and get up to speed with how the templates are defined etc, but if anyone wants to add this feature either locally or contribute then this seems to work ok: npm install --save-dev babel-plugin-transform-react-jsx-source and modifying the webpack rule for babel-loader as below: module: {
rules: [
{ test: /\.tsx?$/, include: /ClientApp/, use: { loader: 'babel-loader', options: { plugins: isDevBuild ? ["transform-react-jsx-source"] : [] } } },
{ test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' }
]
}, |
Addtionally wondering if we shouldn't be setting |
ok decided to man up, pull request incoming :) The cache does speed up the webpack build by 30-40%. |
- Added 'babel-plugin-transform-react-jsx-source' to development build to add line numbers to debug output. - Added 'cacheDirectory: true' to babel config which improves webpack build time c. 40%.
We use |
That might have been where I got the idea from ;) |
Thanks for the suggestion. Since @DanHarman is implementing this in #749, I'll close this one. BTW @gaearon thanks for the wonderful work on Redux. I especially like the docs - really easy and fun to read through. |
@gaearon Do you know if there's some way to make From what I can tell, if we include |
Oh, I see. It uses information as provided by Babel. I don’t know about how TS and Babel interaction is set up so I can’t really answer that. |
OK, thanks for the info! I'll see whether anyone else knows if there's a way to get the original line numbers to flow through somehow. If not, I guess we'd have to just not add this change. |
Maybe @hzoo could say whether there’s a any way to tell Babel to infer the original location information from a TS sourcemap (or something like this) or not. |
I don't think we do anything special with sourcemaps other than use the The location that is referenced ^ is just from the AST passed into Babel that is reading the JSX. Just my thoughts, but I don't think it has to do with sourcemaps because the Babel plugin runs on the source code itself. I believe we'd need to support TS in babylon for this feature |
We'd either have to have Babylon take the input sourcemap into account, or we'd have parse and then iterate over the AST afterward in |
Thanks for the info! If this gets implemented one day, we will change the templates to take advantage of it. In the meantime we'll leave things as-is. |
In Create React App, we enable babel-plugin-transform-react-jsx-source in development configuration. I would suggest you to do the same.
It must only be enabled in development (since it produces bigger bundles). When it is enabled, React warnings get component stack traces with exact line numbers.
Example before:
Example after:
Hope you find this useful!
The text was updated successfully, but these errors were encountered: