From 50a0a5aa4cd80896509335fd26888bf2b36a2e08 Mon Sep 17 00:00:00 2001 From: Jeremy Gayed Date: Sat, 3 Sep 2016 10:33:54 -0400 Subject: [PATCH] Adds JSX extension support (#563) * Adds JSX extension support * PR changes * Add testRegex * Add note about not recommending JSX, link to issue --- config/webpack.config.dev.js | 9 ++++++--- config/webpack.config.prod.js | 9 ++++++--- scripts/utils/createJestConfig.js | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js index 3a97767e1f..e9d5a1f494 100644 --- a/config/webpack.config.dev.js +++ b/config/webpack.config.dev.js @@ -74,7 +74,10 @@ module.exports = { // https://github.com/facebookincubator/create-react-app/issues/253 fallback: paths.nodePaths, // These are the reasonable defaults supported by the Node ecosystem. - extensions: ['.js', '.json', ''], + // We also include JSX as a common component filename extension to support + // some tools, although we do not recommend using it, see: + // https://github.com/facebookincubator/create-react-app/issues/290 + extensions: ['.js', '.json', '.jsx', ''], alias: { // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ @@ -93,7 +96,7 @@ module.exports = { // It's important to do this before Babel processes the JS. preLoaders: [ { - test: /\.js$/, + test: /\.(js|jsx)$/, loader: 'eslint', include: paths.appSrc, } @@ -101,7 +104,7 @@ module.exports = { loaders: [ // Process JS with Babel. { - test: /\.js$/, + test: /\.(js|jsx)$/, include: paths.appSrc, loader: 'babel', query: require('./babel.dev') diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index af9d35df40..be27a29e4b 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -69,7 +69,10 @@ module.exports = { // https://github.com/facebookincubator/create-react-app/issues/253 fallback: paths.nodePaths, // These are the reasonable defaults supported by the Node ecosystem. - extensions: ['.js', '.json', ''], + // We also include JSX as a common component filename extension to support + // some tools, although we do not recommend using it, see: + // https://github.com/facebookincubator/create-react-app/issues/290 + extensions: ['.js', '.json', '.jsx', ''], alias: { // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ @@ -88,7 +91,7 @@ module.exports = { // It's important to do this before Babel processes the JS. preLoaders: [ { - test: /\.js$/, + test: /\.(js|jsx)$/, loader: 'eslint', include: paths.appSrc } @@ -96,7 +99,7 @@ module.exports = { loaders: [ // Process JS with Babel. { - test: /\.js$/, + test: /\.(js|jsx)$/, include: paths.appSrc, loader: 'babel', query: require('./babel.prod') diff --git a/scripts/utils/createJestConfig.js b/scripts/utils/createJestConfig.js index 91c0fb498b..95a550be53 100644 --- a/scripts/utils/createJestConfig.js +++ b/scripts/utils/createJestConfig.js @@ -19,6 +19,7 @@ module.exports = (resolve, rootDir) => { } const config = { + moduleFileExtensions: ['jsx', 'js', 'json'], moduleNameMapper: { '^[./a-zA-Z0-9$_-]+\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'), '^[./a-zA-Z0-9$_-]+\\.css$': resolve('config/jest/CSSStub.js') @@ -26,7 +27,8 @@ module.exports = (resolve, rootDir) => { scriptPreprocessor: resolve('config/jest/transform.js'), setupFiles: setupFiles, testPathIgnorePatterns: ['/(build|docs|node_modules)/'], - testEnvironment: 'node' + testEnvironment: 'node', + testRegex: '(/__tests__/.*|\\.(test|spec))\\.(js|jsx)$', }; if (rootDir) { config.rootDir = rootDir;