Skip to content

Commit 49e4f64

Browse files
tizmagikgaearon
authored andcommitted
Adds JSX extension support (#563)
* Adds JSX extension support * PR changes * Add testRegex * Add note about not recommending JSX, link to issue
1 parent 6da2955 commit 49e4f64

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

config/webpack.config.dev.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ module.exports = {
7474
// https://github.com/facebookincubator/create-react-app/issues/253
7575
fallback: paths.nodePaths,
7676
// These are the reasonable defaults supported by the Node ecosystem.
77-
extensions: ['.js', '.json', ''],
77+
// We also include JSX as a common component filename extension to support
78+
// some tools, although we do not recommend using it, see:
79+
// https://github.com/facebookincubator/create-react-app/issues/290
80+
extensions: ['.js', '.json', '.jsx', ''],
7881
alias: {
7982
// Support React Native Web
8083
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -93,15 +96,15 @@ module.exports = {
9396
// It's important to do this before Babel processes the JS.
9497
preLoaders: [
9598
{
96-
test: /\.js$/,
99+
test: /\.(js|jsx)$/,
97100
loader: 'eslint',
98101
include: paths.appSrc,
99102
}
100103
],
101104
loaders: [
102105
// Process JS with Babel.
103106
{
104-
test: /\.js$/,
107+
test: /\.(js|jsx)$/,
105108
include: paths.appSrc,
106109
loader: 'babel',
107110
query: require('./babel.dev')

config/webpack.config.prod.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ module.exports = {
6969
// https://github.com/facebookincubator/create-react-app/issues/253
7070
fallback: paths.nodePaths,
7171
// These are the reasonable defaults supported by the Node ecosystem.
72-
extensions: ['.js', '.json', ''],
72+
// We also include JSX as a common component filename extension to support
73+
// some tools, although we do not recommend using it, see:
74+
// https://github.com/facebookincubator/create-react-app/issues/290
75+
extensions: ['.js', '.json', '.jsx', ''],
7376
alias: {
7477
// Support React Native Web
7578
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -88,15 +91,15 @@ module.exports = {
8891
// It's important to do this before Babel processes the JS.
8992
preLoaders: [
9093
{
91-
test: /\.js$/,
94+
test: /\.(js|jsx)$/,
9295
loader: 'eslint',
9396
include: paths.appSrc
9497
}
9598
],
9699
loaders: [
97100
// Process JS with Babel.
98101
{
99-
test: /\.js$/,
102+
test: /\.(js|jsx)$/,
100103
include: paths.appSrc,
101104
loader: 'babel',
102105
query: require('./babel.prod')

scripts/utils/createJestConfig.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ module.exports = (resolve, rootDir) => {
1919
}
2020

2121
const config = {
22+
moduleFileExtensions: ['jsx', 'js', 'json'],
2223
moduleNameMapper: {
2324
'^[./a-zA-Z0-9$_-]+\\.(jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm)$': resolve('config/jest/FileStub.js'),
2425
'^[./a-zA-Z0-9$_-]+\\.css$': resolve('config/jest/CSSStub.js')
2526
},
2627
scriptPreprocessor: resolve('config/jest/transform.js'),
2728
setupFiles: setupFiles,
2829
testPathIgnorePatterns: ['<rootDir>/(build|docs|node_modules)/'],
29-
testEnvironment: 'node'
30+
testEnvironment: 'node',
31+
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(js|jsx)$',
3032
};
3133
if (rootDir) {
3234
config.rootDir = rootDir;

0 commit comments

Comments
 (0)