Skip to content

Commit 6512ccd

Browse files
tizmagikGeorge Czabania
authored and
George Czabania
committed
Adds JSX extension support (facebook#563)
* Adds JSX extension support * PR changes * Add testRegex * Add note about not recommending JSX, link to issue
1 parent 72efaae commit 6512ccd

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
@@ -75,7 +75,10 @@ module.exports = {
7575
// https://github.com/facebookincubator/create-react-app/issues/253
7676
fallback: paths.nodePaths,
7777
// These are the reasonable defaults supported by the Node ecosystem.
78-
extensions: ['.js', '.json', ''],
78+
// We also include JSX as a common component filename extension to support
79+
// some tools, although we do not recommend using it, see:
80+
// https://github.com/facebookincubator/create-react-app/issues/290
81+
extensions: ['.js', '.json', '.jsx', ''],
7982
alias: {
8083
// Support React Native Web
8184
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -94,15 +97,15 @@ module.exports = {
9497
// It's important to do this before Babel processes the JS.
9598
preLoaders: [
9699
{
97-
test: /\.js$/,
100+
test: /\.(js|jsx)$/,
98101
loader: 'eslint',
99102
include: paths.appSrc,
100103
}
101104
],
102105
loaders: [
103106
// Process JS with Babel.
104107
{
105-
test: /\.js$/,
108+
test: /\.(js|jsx)$/,
106109
include: paths.appSrc,
107110
loader: 'babel',
108111
query: require('./babel.dev')

config/webpack.config.prod.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ module.exports = {
7070
// https://github.com/facebookincubator/create-react-app/issues/253
7171
fallback: paths.nodePaths,
7272
// These are the reasonable defaults supported by the Node ecosystem.
73-
extensions: ['.js', '.json', ''],
73+
// We also include JSX as a common component filename extension to support
74+
// some tools, although we do not recommend using it, see:
75+
// https://github.com/facebookincubator/create-react-app/issues/290
76+
extensions: ['.js', '.json', '.jsx', ''],
7477
alias: {
7578
// Support React Native Web
7679
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -89,15 +92,15 @@ module.exports = {
8992
// It's important to do this before Babel processes the JS.
9093
preLoaders: [
9194
{
92-
test: /\.js$/,
95+
test: /\.(js|jsx)$/,
9396
loader: 'eslint',
9497
include: paths.appSrc
9598
}
9699
],
97100
loaders: [
98101
// Process JS with Babel.
99102
{
100-
test: /\.js$/,
103+
test: /\.(js|jsx)$/,
101104
include: paths.appSrc,
102105
loader: 'babel',
103106
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)