Skip to content

Commit 736561f

Browse files
authored
Add .mjs support back to webpack (#5258)
* Add `.mjs` support back to webpack, because webpack was not the problem * Continue toggling `.mjs` to `javascript/auto` mode * Be more inline with the specification * Bump old Node to 6
1 parent a5d2e43 commit 736561f

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ matrix:
3131
- os: osx
3232
node_js: 8
3333
env: TEST_SUITE=behavior
34-
- node_js: 4
34+
- node_js: 6
3535
env: TEST_SUITE=old-node

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

+5-15
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ module.exports = {
144144
// https://github.com/facebook/create-react-app/issues/290
145145
// `web` extension prefixes have been added for better support
146146
// for React Native Web.
147-
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
147+
extensions: ['.mjs', '.web.js', '.js', '.json', '.web.jsx', '.jsx'],
148148
alias: {
149149
// Support React Native Web
150150
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -178,7 +178,7 @@ module.exports = {
178178
// First, run the linter.
179179
// It's important to do this before Babel processes the JS.
180180
{
181-
test: /\.(js|jsx)$/,
181+
test: /\.(js|mjs|jsx)$/,
182182
enforce: 'pre',
183183
use: [
184184
{
@@ -199,16 +199,6 @@ module.exports = {
199199
],
200200
include: paths.appSrc,
201201
},
202-
{
203-
// `mjs` support is still in its infancy in the ecosystem, so we don't
204-
// support it.
205-
// Modules who define their `browser` or `module` key as `mjs` force
206-
// the use of this extension, so we need to tell webpack to fall back
207-
// to auto mode (ES Module interop, allows ESM to import CommonJS).
208-
test: /\.mjs$/,
209-
include: /node_modules/,
210-
type: 'javascript/auto',
211-
},
212202
{
213203
// "oneOf" will traverse all following loaders until one will
214204
// match the requirements. When no loader matches it will fall
@@ -228,7 +218,7 @@ module.exports = {
228218
// Process application JS with Babel.
229219
// The preset includes JSX, Flow, and some ESnext features.
230220
{
231-
test: /\.(js|jsx)$/,
221+
test: /\.(js|mjs|jsx)$/,
232222
include: paths.appSrc,
233223
loader: require.resolve('babel-loader'),
234224
options: {
@@ -274,7 +264,7 @@ module.exports = {
274264
// Process any JS outside of the app with Babel.
275265
// Unlike the application JS, we only compile the standard ES features.
276266
{
277-
test: /\.js$/,
267+
test: /\.(js|mjs)$/,
278268
exclude: /@babel(?:\/|\\{1,2})runtime/,
279269
loader: require.resolve('babel-loader'),
280270
options: {
@@ -361,7 +351,7 @@ module.exports = {
361351
// its runtime that would otherwise be processed through "file" loader.
362352
// Also exclude `html` and `json` extensions so they get processed
363353
// by webpacks internal loaders.
364-
exclude: [/\.(js|jsx)$/, /\.html$/, /\.json$/],
354+
exclude: [/\.(js|mjs|jsx)$/, /\.html$/, /\.json$/],
365355
loader: require.resolve('file-loader'),
366356
options: {
367357
name: 'static/media/[name].[hash:8].[ext]',

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

+5-15
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ module.exports = {
210210
// https://github.com/facebook/create-react-app/issues/290
211211
// `web` extension prefixes have been added for better support
212212
// for React Native Web.
213-
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
213+
extensions: ['.mjs', '.web.js', '.js', '.json', '.web.jsx', '.jsx'],
214214
alias: {
215215
// Support React Native Web
216216
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -244,7 +244,7 @@ module.exports = {
244244
// First, run the linter.
245245
// It's important to do this before Babel processes the JS.
246246
{
247-
test: /\.(js|jsx)$/,
247+
test: /\.(js|mjs|jsx)$/,
248248
enforce: 'pre',
249249
use: [
250250
{
@@ -267,16 +267,6 @@ module.exports = {
267267
],
268268
include: paths.appSrc,
269269
},
270-
{
271-
// `mjs` support is still in its infancy in the ecosystem, so we don't
272-
// support it.
273-
// Modules who define their `browser` or `module` key as `mjs` force
274-
// the use of this extension, so we need to tell webpack to fall back
275-
// to auto mode (ES Module interop, allows ESM to import CommonJS).
276-
test: /\.mjs$/,
277-
include: /node_modules/,
278-
type: 'javascript/auto',
279-
},
280270
{
281271
// "oneOf" will traverse all following loaders until one will
282272
// match the requirements. When no loader matches it will fall
@@ -295,7 +285,7 @@ module.exports = {
295285
// Process application JS with Babel.
296286
// The preset includes JSX, Flow, and some ESnext features.
297287
{
298-
test: /\.(js|jsx)$/,
288+
test: /\.(js|mjs|jsx)$/,
299289
include: paths.appSrc,
300290

301291
loader: require.resolve('babel-loader'),
@@ -340,7 +330,7 @@ module.exports = {
340330
// Process any JS outside of the app with Babel.
341331
// Unlike the application JS, we only compile the standard ES features.
342332
{
343-
test: /\.js$/,
333+
test: /\.(js|mjs)$/,
344334
exclude: /@babel(?:\/|\\{1,2})runtime/,
345335
loader: require.resolve('babel-loader'),
346336
options: {
@@ -445,7 +435,7 @@ module.exports = {
445435
// it's runtime that would otherwise be processed through "file" loader.
446436
// Also exclude `html` and `json` extensions so they get processed
447437
// by webpacks internal loaders.
448-
exclude: [/\.(js|jsx)$/, /\.html$/, /\.json$/],
438+
exclude: [/\.(js|mjs|jsx)$/, /\.html$/, /\.json$/],
449439
options: {
450440
name: 'static/media/[name].[hash:8].[ext]',
451441
},

0 commit comments

Comments
 (0)