Commit 49e4f646 authored by Jeremy Gayed's avatar Jeremy Gayed Committed by Dan Abramov
Browse files

Adds JSX extension support (#563)

* Adds JSX extension support

* PR changes

* Add testRegex

* Add note about not recommending JSX, link to issue
parent 6da29550
No related merge requests found
Showing with 15 additions and 7 deletions
+15 -7
...@@ -74,7 +74,10 @@ module.exports = { ...@@ -74,7 +74,10 @@ module.exports = {
// https://github.com/facebookincubator/create-react-app/issues/253 // https://github.com/facebookincubator/create-react-app/issues/253
fallback: paths.nodePaths, fallback: paths.nodePaths,
// These are the reasonable defaults supported by the Node ecosystem. // 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: { alias: {
// Support React Native Web // Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
...@@ -93,7 +96,7 @@ module.exports = { ...@@ -93,7 +96,7 @@ module.exports = {
// It's important to do this before Babel processes the JS. // It's important to do this before Babel processes the JS.
preLoaders: [ preLoaders: [
{ {
test: /\.js$/, test: /\.(js|jsx)$/,
loader: 'eslint', loader: 'eslint',
include: paths.appSrc, include: paths.appSrc,
} }
...@@ -101,7 +104,7 @@ module.exports = { ...@@ -101,7 +104,7 @@ module.exports = {
loaders: [ loaders: [
// Process JS with Babel. // Process JS with Babel.
{ {
test: /\.js$/, test: /\.(js|jsx)$/,
include: paths.appSrc, include: paths.appSrc,
loader: 'babel', loader: 'babel',
query: require('./babel.dev') query: require('./babel.dev')
......
...@@ -69,7 +69,10 @@ module.exports = { ...@@ -69,7 +69,10 @@ module.exports = {
// https://github.com/facebookincubator/create-react-app/issues/253 // https://github.com/facebookincubator/create-react-app/issues/253
fallback: paths.nodePaths, fallback: paths.nodePaths,
// These are the reasonable defaults supported by the Node ecosystem. // 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: { alias: {
// Support React Native Web // Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
...@@ -88,7 +91,7 @@ module.exports = { ...@@ -88,7 +91,7 @@ module.exports = {
// It's important to do this before Babel processes the JS. // It's important to do this before Babel processes the JS.
preLoaders: [ preLoaders: [
{ {
test: /\.js$/, test: /\.(js|jsx)$/,
loader: 'eslint', loader: 'eslint',
include: paths.appSrc include: paths.appSrc
} }
...@@ -96,7 +99,7 @@ module.exports = { ...@@ -96,7 +99,7 @@ module.exports = {
loaders: [ loaders: [
// Process JS with Babel. // Process JS with Babel.
{ {
test: /\.js$/, test: /\.(js|jsx)$/,
include: paths.appSrc, include: paths.appSrc,
loader: 'babel', loader: 'babel',
query: require('./babel.prod') query: require('./babel.prod')
......
...@@ -19,6 +19,7 @@ module.exports = (resolve, rootDir) => { ...@@ -19,6 +19,7 @@ module.exports = (resolve, rootDir) => {
} }
const config = { const config = {
moduleFileExtensions: ['jsx', 'js', 'json'],
moduleNameMapper: { 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$_-]+\\.(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') '^[./a-zA-Z0-9$_-]+\\.css$': resolve('config/jest/CSSStub.js')
...@@ -26,7 +27,8 @@ module.exports = (resolve, rootDir) => { ...@@ -26,7 +27,8 @@ module.exports = (resolve, rootDir) => {
scriptPreprocessor: resolve('config/jest/transform.js'), scriptPreprocessor: resolve('config/jest/transform.js'),
setupFiles: setupFiles, setupFiles: setupFiles,
testPathIgnorePatterns: ['<rootDir>/(build|docs|node_modules)/'], testPathIgnorePatterns: ['<rootDir>/(build|docs|node_modules)/'],
testEnvironment: 'node' testEnvironment: 'node',
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(js|jsx)$',
}; };
if (rootDir) { if (rootDir) {
config.rootDir = rootDir; config.rootDir = rootDir;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment