Skip to content

Commit

Permalink
Add JSX source transform for better warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 23, 2016
1 parent 92afcaf commit 579309f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
16 changes: 16 additions & 0 deletions packages/babel-preset-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ module.exports = {
}]
],
env: {
development: {
plugins: [
// Adds component stack to warning messages
require.resolve('babel-plugin-transform-react-jsx-source'),
// Adds __self attribute to JSX which React will use for some warnings
require.resolve('babel-plugin-transform-react-jsx-self')
]
},
test: {
plugins: [
// Adds component stack to warning messages
require.resolve('babel-plugin-transform-react-jsx-source'),
// Adds __self attribute to JSX which React will use for some warnings
require.resolve('babel-plugin-transform-react-jsx-self')
]
},
production: {
plugins: [
// Optimization: hoist JSX that never changes out of render()
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-preset-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"babel-plugin-transform-class-properties": "6.11.5",
"babel-plugin-transform-object-rest-spread": "6.8.0",
"babel-plugin-transform-react-constant-elements": "6.9.1",
"babel-plugin-transform-react-jsx-self": "6.11.0",
"babel-plugin-transform-react-jsx-source": "6.9.0",
"babel-plugin-transform-regenerator": "6.14.0",
"babel-plugin-transform-runtime": "6.15.0",
"babel-preset-latest": "6.14.0",
Expand Down
8 changes: 5 additions & 3 deletions packages/react-scripts/config/jest/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

const babelJest = require('babel-jest');

module.exports = babelJest.createTransformer({
presets: [require.resolve('babel-preset-react-app')]
});
module.exports = babelJest.createTransformer(
// We embed the preset instead of referring to it because otherwise
// `env` options in the preset do not get taken into account.
require('babel-preset-react-app')
);
14 changes: 10 additions & 4 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ module.exports = {
include: paths.appSrc,
loader: 'babel',
query: {
// @remove-on-eject-begin
babelrc: false,
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-end
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/react-scripts/
// directory for faster rebuilds. We use findCacheDir() because of:
Expand Down Expand Up @@ -226,3 +222,13 @@ module.exports = {
tls: 'empty'
}
};

// @remove-on-eject-begin
// Override babel-loader options to not read .babelrc.
var babelLoader = module.exports.module.loaders.find(l => l.loader === 'babel');
babelLoader.query = babelLoader.query || {};
babelLoader.query.babelrc = false;
// We embed the preset instead of referring to it because otherwise
// `env` options in the preset do not get taken into account.
Object.assign(babelLoader.query, require('babel-preset-react-app'));
// @remove-on-eject-end
18 changes: 11 additions & 7 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,7 @@ module.exports = {
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
// @remove-on-eject-begin
query: {
babelrc: false,
presets: [require.resolve('babel-preset-react-app')],
},
// @remove-on-eject-end
loader: 'babel'
},
// The notation here is somewhat confusing.
// "postcss" loader applies autoprefixer to our CSS.
Expand Down Expand Up @@ -260,3 +254,13 @@ module.exports = {
tls: 'empty'
}
};

// @remove-on-eject-begin
// Override babel-loader options to not read .babelrc.
var babelLoader = module.exports.module.loaders.find(l => l.loader === 'babel');
babelLoader.query = babelLoader.query || {};
babelLoader.query.babelrc = false;
// We embed the preset instead of referring to it because otherwise
// `env` options in the preset do not get taken into account.
Object.assign(babelLoader.query, require('babel-preset-react-app'));
// @remove-on-eject-end

0 comments on commit 579309f

Please sign in to comment.