Skip to content

Commit 5c8000f

Browse files
Timergaearon
authored andcommitted
Add .mjs support (#3239)
1 parent 4add16d commit 5c8000f

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

packages/react-scripts/config/webpack.config.dev.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = {
9292
// https://github.com/facebookincubator/create-react-app/issues/290
9393
// `web` extension prefixes have been added for better support
9494
// for React Native Web.
95-
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
95+
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
9696
alias: {
9797
// @remove-on-eject-begin
9898
// Resolve Babel runtime relative to react-scripts.
@@ -126,7 +126,7 @@ module.exports = {
126126
// First, run the linter.
127127
// It's important to do this before Babel processes the JS.
128128
{
129-
test: /\.(js|jsx)$/,
129+
test: /\.(js|jsx|mjs)$/,
130130
enforce: 'pre',
131131
use: [
132132
{
@@ -164,7 +164,7 @@ module.exports = {
164164
},
165165
// Process JS with Babel.
166166
{
167-
test: /\.(js|jsx)$/,
167+
test: /\.(js|jsx|mjs)$/,
168168
include: paths.appSrc,
169169
loader: require.resolve('babel-loader'),
170170
options: {

packages/react-scripts/config/webpack.config.prod.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module.exports = {
9696
// https://github.com/facebookincubator/create-react-app/issues/290
9797
// `web` extension prefixes have been added for better support
9898
// for React Native Web.
99-
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
99+
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
100100
alias: {
101101
// @remove-on-eject-begin
102102
// Resolve Babel runtime relative to react-scripts.
@@ -130,7 +130,7 @@ module.exports = {
130130
// First, run the linter.
131131
// It's important to do this before Babel processes the JS.
132132
{
133-
test: /\.(js|jsx)$/,
133+
test: /\.(js|jsx|mjs)$/,
134134
enforce: 'pre',
135135
use: [
136136
{
@@ -169,7 +169,7 @@ module.exports = {
169169
},
170170
// Process JS with Babel.
171171
{
172-
test: /\.(js|jsx)$/,
172+
test: /\.(js|jsx|mjs)$/,
173173
include: paths.appSrc,
174174
loader: require.resolve('babel-loader'),
175175
options: {

packages/react-scripts/scripts/utils/createJestConfig.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,37 @@ module.exports = (resolve, rootDir, isEjecting) => {
2121
// TODO: I don't know if it's safe or not to just use / as path separator
2222
// in Jest configs. We need help from somebody with Windows to determine this.
2323
const config = {
24-
collectCoverageFrom: ['src/**/*.{js,jsx}'],
24+
collectCoverageFrom: ['src/**/*.{js,jsx,mjs}'],
2525
setupFiles: [resolve('config/polyfills.js')],
2626
setupTestFrameworkScriptFile: setupTestsFile,
2727
testMatch: [
28-
'<rootDir>/src/**/__tests__/**/*.js?(x)',
29-
'<rootDir>/src/**/?(*.)(spec|test).js?(x)',
28+
'<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}',
29+
'<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}',
3030
],
3131
testEnvironment: 'node',
3232
testURL: 'http://localhost',
3333
transform: {
34-
'^.+\\.(js|jsx)$': isEjecting
34+
'^.+\\.(js|jsx|mjs)$': isEjecting
3535
? '<rootDir>/node_modules/babel-jest'
3636
: resolve('config/jest/babelTransform.js'),
3737
'^.+\\.css$': resolve('config/jest/cssTransform.js'),
38-
'^(?!.*\\.(js|jsx|css|json)$)': resolve('config/jest/fileTransform.js'),
38+
'^(?!.*\\.(js|jsx|mjs|css|json)$)': resolve(
39+
'config/jest/fileTransform.js'
40+
),
3941
},
40-
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
42+
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$'],
4143
moduleNameMapper: {
4244
'^react-native$': 'react-native-web',
4345
},
44-
moduleFileExtensions: ['web.js', 'js', 'json', 'web.jsx', 'jsx', 'node'],
46+
moduleFileExtensions: [
47+
'web.js',
48+
'mjs',
49+
'js',
50+
'json',
51+
'web.jsx',
52+
'jsx',
53+
'node',
54+
],
4555
};
4656
if (rootDir) {
4757
config.rootDir = rootDir;

0 commit comments

Comments
 (0)