mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-30 02:15:52 +08:00
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
This commit is contained in:
@@ -31,5 +31,5 @@ matrix:
|
|||||||
- os: osx
|
- os: osx
|
||||||
node_js: 8
|
node_js: 8
|
||||||
env: TEST_SUITE=behavior
|
env: TEST_SUITE=behavior
|
||||||
- node_js: 4
|
- node_js: 6
|
||||||
env: TEST_SUITE=old-node
|
env: TEST_SUITE=old-node
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ module.exports = {
|
|||||||
// https://github.com/facebook/create-react-app/issues/290
|
// https://github.com/facebook/create-react-app/issues/290
|
||||||
// `web` extension prefixes have been added for better support
|
// `web` extension prefixes have been added for better support
|
||||||
// for React Native Web.
|
// for React Native Web.
|
||||||
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
|
extensions: ['.mjs', '.web.js', '.js', '.json', '.web.jsx', '.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/
|
||||||
@@ -178,7 +178,7 @@ module.exports = {
|
|||||||
// First, run the linter.
|
// First, run the linter.
|
||||||
// It's important to do this before Babel processes the JS.
|
// It's important to do this before Babel processes the JS.
|
||||||
{
|
{
|
||||||
test: /\.(js|jsx)$/,
|
test: /\.(js|mjs|jsx)$/,
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
use: [
|
use: [
|
||||||
{
|
{
|
||||||
@@ -199,16 +199,6 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
include: paths.appSrc,
|
include: paths.appSrc,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
// `mjs` support is still in its infancy in the ecosystem, so we don't
|
|
||||||
// support it.
|
|
||||||
// Modules who define their `browser` or `module` key as `mjs` force
|
|
||||||
// the use of this extension, so we need to tell webpack to fall back
|
|
||||||
// to auto mode (ES Module interop, allows ESM to import CommonJS).
|
|
||||||
test: /\.mjs$/,
|
|
||||||
include: /node_modules/,
|
|
||||||
type: 'javascript/auto',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
// "oneOf" will traverse all following loaders until one will
|
// "oneOf" will traverse all following loaders until one will
|
||||||
// match the requirements. When no loader matches it will fall
|
// match the requirements. When no loader matches it will fall
|
||||||
@@ -228,7 +218,7 @@ module.exports = {
|
|||||||
// Process application JS with Babel.
|
// Process application JS with Babel.
|
||||||
// The preset includes JSX, Flow, and some ESnext features.
|
// The preset includes JSX, Flow, and some ESnext features.
|
||||||
{
|
{
|
||||||
test: /\.(js|jsx)$/,
|
test: /\.(js|mjs|jsx)$/,
|
||||||
include: paths.appSrc,
|
include: paths.appSrc,
|
||||||
loader: require.resolve('babel-loader'),
|
loader: require.resolve('babel-loader'),
|
||||||
options: {
|
options: {
|
||||||
@@ -274,7 +264,7 @@ module.exports = {
|
|||||||
// Process any JS outside of the app with Babel.
|
// Process any JS outside of the app with Babel.
|
||||||
// Unlike the application JS, we only compile the standard ES features.
|
// Unlike the application JS, we only compile the standard ES features.
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.(js|mjs)$/,
|
||||||
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
||||||
loader: require.resolve('babel-loader'),
|
loader: require.resolve('babel-loader'),
|
||||||
options: {
|
options: {
|
||||||
@@ -361,7 +351,7 @@ module.exports = {
|
|||||||
// its runtime that would otherwise be processed through "file" loader.
|
// its runtime that would otherwise be processed through "file" loader.
|
||||||
// Also exclude `html` and `json` extensions so they get processed
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
// by webpacks internal loaders.
|
// by webpacks internal loaders.
|
||||||
exclude: [/\.(js|jsx)$/, /\.html$/, /\.json$/],
|
exclude: [/\.(js|mjs|jsx)$/, /\.html$/, /\.json$/],
|
||||||
loader: require.resolve('file-loader'),
|
loader: require.resolve('file-loader'),
|
||||||
options: {
|
options: {
|
||||||
name: 'static/media/[name].[hash:8].[ext]',
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ module.exports = {
|
|||||||
// https://github.com/facebook/create-react-app/issues/290
|
// https://github.com/facebook/create-react-app/issues/290
|
||||||
// `web` extension prefixes have been added for better support
|
// `web` extension prefixes have been added for better support
|
||||||
// for React Native Web.
|
// for React Native Web.
|
||||||
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
|
extensions: ['.mjs', '.web.js', '.js', '.json', '.web.jsx', '.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/
|
||||||
@@ -244,7 +244,7 @@ module.exports = {
|
|||||||
// First, run the linter.
|
// First, run the linter.
|
||||||
// It's important to do this before Babel processes the JS.
|
// It's important to do this before Babel processes the JS.
|
||||||
{
|
{
|
||||||
test: /\.(js|jsx)$/,
|
test: /\.(js|mjs|jsx)$/,
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
use: [
|
use: [
|
||||||
{
|
{
|
||||||
@@ -267,16 +267,6 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
include: paths.appSrc,
|
include: paths.appSrc,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
// `mjs` support is still in its infancy in the ecosystem, so we don't
|
|
||||||
// support it.
|
|
||||||
// Modules who define their `browser` or `module` key as `mjs` force
|
|
||||||
// the use of this extension, so we need to tell webpack to fall back
|
|
||||||
// to auto mode (ES Module interop, allows ESM to import CommonJS).
|
|
||||||
test: /\.mjs$/,
|
|
||||||
include: /node_modules/,
|
|
||||||
type: 'javascript/auto',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
// "oneOf" will traverse all following loaders until one will
|
// "oneOf" will traverse all following loaders until one will
|
||||||
// match the requirements. When no loader matches it will fall
|
// match the requirements. When no loader matches it will fall
|
||||||
@@ -295,7 +285,7 @@ module.exports = {
|
|||||||
// Process application JS with Babel.
|
// Process application JS with Babel.
|
||||||
// The preset includes JSX, Flow, and some ESnext features.
|
// The preset includes JSX, Flow, and some ESnext features.
|
||||||
{
|
{
|
||||||
test: /\.(js|jsx)$/,
|
test: /\.(js|mjs|jsx)$/,
|
||||||
include: paths.appSrc,
|
include: paths.appSrc,
|
||||||
|
|
||||||
loader: require.resolve('babel-loader'),
|
loader: require.resolve('babel-loader'),
|
||||||
@@ -340,7 +330,7 @@ module.exports = {
|
|||||||
// Process any JS outside of the app with Babel.
|
// Process any JS outside of the app with Babel.
|
||||||
// Unlike the application JS, we only compile the standard ES features.
|
// Unlike the application JS, we only compile the standard ES features.
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.(js|mjs)$/,
|
||||||
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
||||||
loader: require.resolve('babel-loader'),
|
loader: require.resolve('babel-loader'),
|
||||||
options: {
|
options: {
|
||||||
@@ -445,7 +435,7 @@ module.exports = {
|
|||||||
// it's runtime that would otherwise be processed through "file" loader.
|
// it's runtime that would otherwise be processed through "file" loader.
|
||||||
// Also exclude `html` and `json` extensions so they get processed
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
// by webpacks internal loaders.
|
// by webpacks internal loaders.
|
||||||
exclude: [/\.(js|jsx)$/, /\.html$/, /\.json$/],
|
exclude: [/\.(js|mjs|jsx)$/, /\.html$/, /\.json$/],
|
||||||
options: {
|
options: {
|
||||||
name: 'static/media/[name].[hash:8].[ext]',
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user