From 4da3d8c6102e8a1532085cb5c42d14aeb6cd928d Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 16:15:56 +0100 Subject: [PATCH 01/32] chore(react-scripts): add appIncludes --- packages/react-scripts/config/paths.js | 2 +- packages/react-scripts/config/webpack.config.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index acaca7f4d48..20c162738e2 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -15,7 +15,7 @@ const url = require('url'); // Make sure any symlinks in the project folder are resolved: // https://github.com/facebook/create-react-app/issues/637 const appDirectory = fs.realpathSync(process.cwd()); -const resolveApp = relativePath => path.resolve(appDirectory, relativePath); +export const resolveApp = relativePath => path.resolve(appDirectory, relativePath); const envPublicUrl = process.env.PUBLIC_URL; diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index bad4290061b..107f46d5472 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -59,6 +59,12 @@ const cssModuleRegex = /\.module\.css$/; const sassRegex = /\.(scss|sass)$/; const sassModuleRegex = /\.module\.(scss|sass)$/; +// our packages that will now be included in the CRA build step +const appIncludes = [ + paths.appSrc, + paths.resolveApp('../components/src'), +] + // This is the production and development configuration. // It is focused on developer experience, fast rebuilds, and a minimal bundle. module.exports = function(webpackEnv) { @@ -381,7 +387,7 @@ module.exports = function(webpackEnv) { loader: require.resolve('eslint-loader'), }, ], - include: paths.appSrc, + include: appIncludes, }, { // "oneOf" will traverse all following loaders until one will @@ -403,7 +409,7 @@ module.exports = function(webpackEnv) { // The preset includes JSX, Flow, TypeScript, and some ESnext features. { test: /\.(js|mjs|jsx|ts|tsx)$/, - include: paths.appSrc, + include: appIncludes, loader: require.resolve('babel-loader'), options: { customize: require.resolve( From 19ffe5c1b49f1c73edd98e05faf7d78ba48cf738 Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 16:19:29 +0100 Subject: [PATCH 02/32] chore(react-scripts): update package.json --- packages/react-scripts/package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 18c63e4b154..d2d03a3579b 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,10 +1,10 @@ { - "name": "react-scripts", + "name": "nos-react-scripts", "version": "3.3.0", - "description": "Configuration and scripts for Create React App.", + "description": "nOS Configuration and scripts for Create React App.", "repository": { "type": "git", - "url": "https://github.com/facebook/create-react-app.git", + "url": "https://github.com/nos/create-react-app.git", "directory": "packages/react-scripts" }, "license": "MIT", @@ -12,7 +12,7 @@ "node": ">=8.10" }, "bugs": { - "url": "https://github.com/facebook/create-react-app/issues" + "url": "https://github.com/nos/create-react-app/issues" }, "files": [ "bin", From 3118b6a0db18a44dbd9ad25a9febce7dc7e465f8 Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 16:38:21 +0100 Subject: [PATCH 03/32] chore(react-scripts): update package.json --- packages/react-scripts/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index d2d03a3579b..da596c2f80b 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,5 +1,5 @@ { - "name": "nos-react-scripts", + "name": "@nosplatform/react-scripts", "version": "3.3.0", "description": "nOS Configuration and scripts for Create React App.", "repository": { @@ -107,5 +107,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "publishConfig": { + "access": "public" } } From 06891a02d44e4cb4983ebbb3db2016fd08e99a15 Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 18:07:35 +0100 Subject: [PATCH 04/32] chore(react-scripts): fix export --- packages/react-scripts/config/paths.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 20c162738e2..c58a893ef8f 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -15,7 +15,7 @@ const url = require('url'); // Make sure any symlinks in the project folder are resolved: // https://github.com/facebook/create-react-app/issues/637 const appDirectory = fs.realpathSync(process.cwd()); -export const resolveApp = relativePath => path.resolve(appDirectory, relativePath); +const resolveApp = relativePath => path.resolve(appDirectory, relativePath); const envPublicUrl = process.env.PUBLIC_URL; @@ -75,6 +75,7 @@ const resolveModule = (resolveFn, filePath) => { // config after eject: we're in ./config/ module.exports = { + resolveApp, dotenv: resolveApp('.env'), appPath: resolveApp('.'), appBuild: resolveApp('build'), @@ -98,6 +99,7 @@ const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath); // config before eject: we're in ./node_modules/react-scripts/config/ module.exports = { + resolveApp, dotenv: resolveApp('.env'), appPath: resolveApp('.'), appBuild: resolveApp('build'), @@ -134,6 +136,7 @@ if ( ) { const templatePath = '../cra-template/template'; module.exports = { + resolveApp, dotenv: resolveOwn(`${templatePath}/.env`), appPath: resolveApp('.'), appBuild: resolveOwn('../../build'), From a5c08733e204fa6b8ba97203914ac97abc02d7eb Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 18:08:13 +0100 Subject: [PATCH 05/32] v3.3.1 --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index da596c2f80b..c252b9a0fde 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@nosplatform/react-scripts", - "version": "3.3.0", + "version": "3.3.1", "description": "nOS Configuration and scripts for Create React App.", "repository": { "type": "git", From 493b8c2bd286001dc8b296defffb377b6d68f989 Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 19:16:46 +0100 Subject: [PATCH 06/32] chore(react-scripts): adjust webpack config --- packages/react-scripts/config/paths.js | 3 --- .../react-scripts/config/webpack.config.js | 21 +++++++++---------- packages/react-scripts/package.json | 2 ++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index c58a893ef8f..acaca7f4d48 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -75,7 +75,6 @@ const resolveModule = (resolveFn, filePath) => { // config after eject: we're in ./config/ module.exports = { - resolveApp, dotenv: resolveApp('.env'), appPath: resolveApp('.'), appBuild: resolveApp('build'), @@ -99,7 +98,6 @@ const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath); // config before eject: we're in ./node_modules/react-scripts/config/ module.exports = { - resolveApp, dotenv: resolveApp('.env'), appPath: resolveApp('.'), appBuild: resolveApp('build'), @@ -136,7 +134,6 @@ if ( ) { const templatePath = '../cra-template/template'; module.exports = { - resolveApp, dotenv: resolveOwn(`${templatePath}/.env`), appPath: resolveApp('.'), appBuild: resolveOwn('../../build'), diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 107f46d5472..1c752084476 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -24,7 +24,6 @@ const ManifestPlugin = require('webpack-manifest-plugin'); const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); const WorkboxWebpackPlugin = require('workbox-webpack-plugin'); const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); -const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent'); const paths = require('./paths'); const modules = require('./modules'); @@ -59,11 +58,9 @@ const cssModuleRegex = /\.module\.css$/; const sassRegex = /\.(scss|sass)$/; const sassModuleRegex = /\.module\.(scss|sass)$/; -// our packages that will now be included in the CRA build step -const appIncludes = [ - paths.appSrc, - paths.resolveApp('../components/src'), -] +const pgks = spawn.sync('yarn', ['workspaces', 'info', '--json']); +const output = JSON.parse(pgks.output[1].toString()); +const packages = JSON.parse(output.data); // This is the production and development configuration. // It is focused on developer experience, fast rebuilds, and a minimal bundle. @@ -276,8 +273,8 @@ module.exports = function(webpackEnv) { : false, }, cssProcessorPluginOptions: { - preset: ['default', { minifyFontValues: { removeQuotes: false } }] - } + preset: ['default', { minifyFontValues: { removeQuotes: false } }], + }, }), ], // Automatically split vendor and commons @@ -331,7 +328,7 @@ module.exports = function(webpackEnv) { // To fix this, we prevent you from importing files out of src/ -- if you'd like to, // please link the files into your node_modules/ and let module-resolution kick in. // Make sure your source files are compiled, as they will not be processed in any way. - new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), + // new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), ], }, resolveLoader: { @@ -387,7 +384,7 @@ module.exports = function(webpackEnv) { loader: require.resolve('eslint-loader'), }, ], - include: appIncludes, + include: paths.appSrc, }, { // "oneOf" will traverse all following loaders until one will @@ -409,7 +406,9 @@ module.exports = function(webpackEnv) { // The preset includes JSX, Flow, TypeScript, and some ESnext features. { test: /\.(js|mjs|jsx|ts|tsx)$/, - include: appIncludes, + include: Object.keys(packages).map(_ => + path.join(root, packages[_].location) + ), loader: require.resolve('babel-loader'), options: { customize: require.resolve( diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index c252b9a0fde..847cb6dd53f 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -39,6 +39,7 @@ "babel-preset-react-app": "^9.1.0", "camelcase": "^5.3.1", "case-sensitive-paths-webpack-plugin": "2.2.0", + "cross-spawn": "^7.0.1", "css-loader": "3.3.2", "dotenv": "8.2.0", "dotenv-expand": "5.1.0", @@ -51,6 +52,7 @@ "eslint-plugin-react": "7.17.0", "eslint-plugin-react-hooks": "^1.6.1", "file-loader": "4.3.0", + "find-yarn-workspace-root": "^1.2.1", "fs-extra": "^8.1.0", "html-webpack-plugin": "4.0.0-beta.11", "identity-obj-proxy": "3.0.0", From 2de5ad88cdd18b3aa0f87d21bae231d42b32737d Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 19:18:45 +0100 Subject: [PATCH 07/32] chore(react-scripts): remove commas From 1866ce3d7b22cfa3c67a2366cbf0d25ca1e8a7fb Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 19:20:44 +0100 Subject: [PATCH 08/32] v3.3.2 --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 847cb6dd53f..eb65772017c 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@nosplatform/react-scripts", - "version": "3.3.1", + "version": "3.3.2", "description": "nOS Configuration and scripts for Create React App.", "repository": { "type": "git", From ea941ee9a1b42a005a603d1be52cfbd90af5b50e Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 19:25:37 +0100 Subject: [PATCH 09/32] chore(react-scripts): add missing imports --- packages/react-scripts/config/webpack.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 1c752084476..856bd54aa78 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -28,6 +28,8 @@ const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent') const paths = require('./paths'); const modules = require('./modules'); const getClientEnvironment = require('./env'); +const spawn = require('cross-spawn'); +const root = require('find-yarn-workspace-root')(); const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin'); const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin'); const typescriptFormatter = require('react-dev-utils/typescriptFormatter'); From e2b43949b07d4db2b1954bbfe5482410b0cdcd4b Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 19:25:58 +0100 Subject: [PATCH 10/32] v3.3.3 --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index eb65772017c..79352771d9e 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@nosplatform/react-scripts", - "version": "3.3.2", + "version": "3.3.3", "description": "nOS Configuration and scripts for Create React App.", "repository": { "type": "git", From 6be812a09321da7a16d761d5c61695c8fd365d3a Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 19:53:25 +0100 Subject: [PATCH 11/32] chore(react-scripts): add error handling when not in monorepo --- .../react-scripts/config/webpack.config.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 856bd54aa78..077a27ae547 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -60,9 +60,17 @@ const cssModuleRegex = /\.module\.css$/; const sassRegex = /\.(scss|sass)$/; const sassModuleRegex = /\.module\.(scss|sass)$/; -const pgks = spawn.sync('yarn', ['workspaces', 'info', '--json']); -const output = JSON.parse(pgks.output[1].toString()); -const packages = JSON.parse(output.data); +let includedSources; +if (root) { + const pgks = spawn.sync('yarn', ['workspaces', 'info', '--json']); + const output = JSON.parse(pgks.output[1].toString()); + const packages = JSON.parse(output.data); + includedSources = Object.keys(packages).map(_ => + path.join(root, packages[_].location) + ); +} else { + includedSources = paths.appSrc; +} // This is the production and development configuration. // It is focused on developer experience, fast rebuilds, and a minimal bundle. @@ -408,9 +416,7 @@ module.exports = function(webpackEnv) { // The preset includes JSX, Flow, TypeScript, and some ESnext features. { test: /\.(js|mjs|jsx|ts|tsx)$/, - include: Object.keys(packages).map(_ => - path.join(root, packages[_].location) - ), + include: includedSources, loader: require.resolve('babel-loader'), options: { customize: require.resolve( From d359f16729039eec0311ab5d2f6676584b4b4a52 Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 19:53:53 +0100 Subject: [PATCH 12/32] v3.3.4 --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 79352771d9e..c7361c37e7c 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@nosplatform/react-scripts", - "version": "3.3.3", + "version": "3.3.4", "description": "nOS Configuration and scripts for Create React App.", "repository": { "type": "git", From 5829bc2a1d9c6e3dde6fc64a22eeabaf28779889 Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 22 Dec 2019 21:38:08 +0100 Subject: [PATCH 13/32] chore(react-scripts): bump version --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index c7361c37e7c..66eb3f93624 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@nosplatform/react-scripts", - "version": "3.3.4", + "version": "3.3.6", "description": "nOS Configuration and scripts for Create React App.", "repository": { "type": "git", From 66eecb122e99d360a2b10987709b5de12b938e52 Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Mon, 6 Jan 2020 20:59:00 +0100 Subject: [PATCH 14/32] chore(react-scripts): delete file --- packages/react-scripts/bin/react-scripts.js | 58 --------------------- 1 file changed, 58 deletions(-) delete mode 100755 packages/react-scripts/bin/react-scripts.js diff --git a/packages/react-scripts/bin/react-scripts.js b/packages/react-scripts/bin/react-scripts.js deleted file mode 100755 index 7e6e290251a..00000000000 --- a/packages/react-scripts/bin/react-scripts.js +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env node -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -'use strict'; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -const spawn = require('react-dev-utils/crossSpawn'); -const args = process.argv.slice(2); - -const scriptIndex = args.findIndex( - x => x === 'build' || x === 'eject' || x === 'start' || x === 'test' -); -const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; -const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; - -if (['build', 'eject', 'start', 'test'].includes(script)) { - const result = spawn.sync( - 'node', - nodeArgs - .concat(require.resolve('../scripts/' + script)) - .concat(args.slice(scriptIndex + 1)), - { stdio: 'inherit' } - ); - if (result.signal) { - if (result.signal === 'SIGKILL') { - console.log( - 'The build failed because the process exited too early. ' + - 'This probably means the system ran out of memory or someone called ' + - '`kill -9` on the process.' - ); - } else if (result.signal === 'SIGTERM') { - console.log( - 'The build failed because the process exited too early. ' + - 'Someone might have called `kill` or `killall`, or the system could ' + - 'be shutting down.' - ); - } - process.exit(1); - } - process.exit(result.status); -} else { - console.log('Unknown script "' + script + '".'); - console.log('Perhaps you need to update react-scripts?'); - console.log( - 'See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases' - ); -} From af71664311df20e17eec9b5984083a62ac5917dd Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Mon, 6 Jan 2020 21:00:06 +0100 Subject: [PATCH 15/32] chore(react-script): re-add file --- packages/react-scripts/bin/react-scripts.js | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 packages/react-scripts/bin/react-scripts.js diff --git a/packages/react-scripts/bin/react-scripts.js b/packages/react-scripts/bin/react-scripts.js new file mode 100644 index 00000000000..7e6e290251a --- /dev/null +++ b/packages/react-scripts/bin/react-scripts.js @@ -0,0 +1,58 @@ +#!/usr/bin/env node +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +'use strict'; + +// Makes the script crash on unhandled rejections instead of silently +// ignoring them. In the future, promise rejections that are not handled will +// terminate the Node.js process with a non-zero exit code. +process.on('unhandledRejection', err => { + throw err; +}); + +const spawn = require('react-dev-utils/crossSpawn'); +const args = process.argv.slice(2); + +const scriptIndex = args.findIndex( + x => x === 'build' || x === 'eject' || x === 'start' || x === 'test' +); +const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; +const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; + +if (['build', 'eject', 'start', 'test'].includes(script)) { + const result = spawn.sync( + 'node', + nodeArgs + .concat(require.resolve('../scripts/' + script)) + .concat(args.slice(scriptIndex + 1)), + { stdio: 'inherit' } + ); + if (result.signal) { + if (result.signal === 'SIGKILL') { + console.log( + 'The build failed because the process exited too early. ' + + 'This probably means the system ran out of memory or someone called ' + + '`kill -9` on the process.' + ); + } else if (result.signal === 'SIGTERM') { + console.log( + 'The build failed because the process exited too early. ' + + 'Someone might have called `kill` or `killall`, or the system could ' + + 'be shutting down.' + ); + } + process.exit(1); + } + process.exit(result.status); +} else { + console.log('Unknown script "' + script + '".'); + console.log('Perhaps you need to update react-scripts?'); + console.log( + 'See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases' + ); +} From 1d123672ce982a58f56cd13e0b702721411e98f5 Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Mon, 6 Jan 2020 21:26:29 +0100 Subject: [PATCH 16/32] chore(react-scripts): bump version --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 66eb3f93624..44913d94dcf 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@nosplatform/react-scripts", - "version": "3.3.6", + "version": "3.3.7", "description": "nOS Configuration and scripts for Create React App.", "repository": { "type": "git", From ccfe9910964d85f8b57027a7c64bc91f81ff4a0c Mon Sep 17 00:00:00 2001 From: Maurice Dalderup Date: Sun, 1 Mar 2020 13:21:44 +0100 Subject: [PATCH 17/32] chore(app): remove file --- .../react-scripts/config/webpack.config.js | 746 ------------------ 1 file changed, 746 deletions(-) delete mode 100644 packages/react-scripts/config/webpack.config.js diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js deleted file mode 100644 index 363c072f8b2..00000000000 --- a/packages/react-scripts/config/webpack.config.js +++ /dev/null @@ -1,746 +0,0 @@ -// @remove-on-eject-begin -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ -// @remove-on-eject-end -'use strict'; - -const fs = require('fs'); -const path = require('path'); -const webpack = require('webpack'); -const resolve = require('resolve'); -const PnpWebpackPlugin = require('pnp-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); -const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); -const safePostCssParser = require('postcss-safe-parser'); -const ManifestPlugin = require('webpack-manifest-plugin'); -const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); -const WorkboxWebpackPlugin = require('workbox-webpack-plugin'); -const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); -const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent'); -const paths = require('./paths'); -const modules = require('./modules'); -const getClientEnvironment = require('./env'); -const spawn = require('cross-spawn'); -const root = require('find-yarn-workspace-root')(); -const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin'); -const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin'); -const typescriptFormatter = require('react-dev-utils/typescriptFormatter'); -// @remove-on-eject-begin -const eslint = require('eslint'); -const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier'); -// @remove-on-eject-end -const postcssNormalize = require('postcss-normalize'); - -const appPackageJson = require(paths.appPackageJson); - -// Source maps are resource heavy and can cause out of memory issue for large source files. -const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'; -// Some apps do not need the benefits of saving a web request, so not inlining the chunk -// makes for a smoother build process. -const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false'; - -const imageInlineSizeLimit = parseInt( - process.env.IMAGE_INLINE_SIZE_LIMIT || '10000' -); - -// Check if TypeScript is setup -const useTypeScript = fs.existsSync(paths.appTsConfig); - -// style files regexes -const cssRegex = /\.css$/; -const cssModuleRegex = /\.module\.css$/; -const sassRegex = /\.(scss|sass)$/; -const sassModuleRegex = /\.module\.(scss|sass)$/; - -let includedSources; -if (root) { - const pgks = spawn.sync('yarn', ['workspaces', 'info', '--json']); - const output = JSON.parse(pgks.output[1].toString()); - const packages = JSON.parse(output.data); - includedSources = Object.keys(packages).map(_ => - path.join(root, packages[_].location) - ); -} else { - includedSources = paths.appSrc; -} - -// This is the production and development configuration. -// It is focused on developer experience, fast rebuilds, and a minimal bundle. -module.exports = function(webpackEnv) { - const isEnvDevelopment = webpackEnv === 'development'; - const isEnvProduction = webpackEnv === 'production'; - - // Variable used for enabling profiling in Production - // passed into alias object. Uses a flag if passed into the build command - const isEnvProductionProfile = - isEnvProduction && process.argv.includes('--profile'); - - // We will provide `paths.publicUrlOrPath` to our app - // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript. - // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz. - // Get environment variables to inject into our app. - const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1)); - - // common function to get style loaders - const getStyleLoaders = (cssOptions, preProcessor) => { - const loaders = [ - isEnvDevelopment && require.resolve('style-loader'), - isEnvProduction && { - loader: MiniCssExtractPlugin.loader, - // css is located in `static/css`, use '../../' to locate index.html folder - // in production `paths.publicUrlOrPath` can be a relative path - options: paths.publicUrlOrPath.startsWith('.') - ? { publicPath: '../../' } - : {}, - }, - { - loader: require.resolve('css-loader'), - options: cssOptions, - }, - { - // Options for PostCSS as we reference these options twice - // Adds vendor prefixing based on your specified browser support in - // package.json - loader: require.resolve('postcss-loader'), - options: { - // Necessary for external CSS imports to work - // https://github.com/facebook/create-react-app/issues/2677 - ident: 'postcss', - plugins: () => [ - require('postcss-flexbugs-fixes'), - require('postcss-preset-env')({ - autoprefixer: { - flexbox: 'no-2009', - }, - stage: 3, - }), - // Adds PostCSS Normalize as the reset css with default options, - // so that it honors browserslist config in package.json - // which in turn let's users customize the target behavior as per their needs. - postcssNormalize(), - ], - sourceMap: isEnvProduction && shouldUseSourceMap, - }, - }, - ].filter(Boolean); - if (preProcessor) { - loaders.push( - { - loader: require.resolve('resolve-url-loader'), - options: { - sourceMap: isEnvProduction && shouldUseSourceMap, - }, - }, - { - loader: require.resolve(preProcessor), - options: { - sourceMap: true, - }, - } - ); - } - return loaders; - }; - - return { - mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development', - // Stop compilation early in production - bail: isEnvProduction, - devtool: isEnvProduction - ? shouldUseSourceMap - ? 'source-map' - : false - : isEnvDevelopment && 'cheap-module-source-map', - // These are the "entry points" to our application. - // This means they will be the "root" imports that are included in JS bundle. - entry: [ - // Include an alternative client for WebpackDevServer. A client's job is to - // connect to WebpackDevServer by a socket and get notified about changes. - // When you save a file, the client will either apply hot updates (in case - // of CSS changes), or refresh the page (in case of JS changes). When you - // make a syntax error, this client will display a syntax error overlay. - // Note: instead of the default WebpackDevServer client, we use a custom one - // to bring better experience for Create React App users. You can replace - // the line below with these two lines if you prefer the stock client: - // require.resolve('webpack-dev-server/client') + '?/', - // require.resolve('webpack/hot/dev-server'), - isEnvDevelopment && - require.resolve('react-dev-utils/webpackHotDevClient'), - // Finally, this is your app's code: - paths.appIndexJs, - // We include the app code last so that if there is a runtime error during - // initialization, it doesn't blow up the WebpackDevServer client, and - // changing JS code would still trigger a refresh. - ].filter(Boolean), - output: { - // The build folder. - path: isEnvProduction ? paths.appBuild : undefined, - // Add /* filename */ comments to generated require()s in the output. - pathinfo: isEnvDevelopment, - // There will be one main bundle, and one file per asynchronous chunk. - // In development, it does not produce real files. - filename: isEnvProduction - ? 'static/js/[name].[contenthash:8].js' - : isEnvDevelopment && 'static/js/bundle.js', - // TODO: remove this when upgrading to webpack 5 - futureEmitAssets: true, - // There are also additional JS chunk files if you use code splitting. - chunkFilename: isEnvProduction - ? 'static/js/[name].[contenthash:8].chunk.js' - : isEnvDevelopment && 'static/js/[name].chunk.js', - // webpack uses `publicPath` to determine where the app is being served from. - // It requires a trailing slash, or the file assets will get an incorrect path. - // We inferred the "public path" (such as / or /my-project) from homepage. - publicPath: paths.publicUrlOrPath, - // Point sourcemap entries to original disk location (format as URL on Windows) - devtoolModuleFilenameTemplate: isEnvProduction - ? info => - path - .relative(paths.appSrc, info.absoluteResourcePath) - .replace(/\\/g, '/') - : isEnvDevelopment && - (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')), - // Prevents conflicts when multiple webpack runtimes (from different apps) - // are used on the same page. - jsonpFunction: `webpackJsonp${appPackageJson.name}`, - // this defaults to 'window', but by setting it to 'this' then - // module chunks which are built will work in web workers as well. - globalObject: 'this', - }, - optimization: { - minimize: isEnvProduction, - minimizer: [ - // This is only used in production mode - new TerserPlugin({ - terserOptions: { - parse: { - // We want terser to parse ecma 8 code. However, we don't want it - // to apply any minification steps that turns valid ecma 5 code - // into invalid ecma 5 code. This is why the 'compress' and 'output' - // sections only apply transformations that are ecma 5 safe - // https://github.com/facebook/create-react-app/pull/4234 - ecma: 8, - }, - compress: { - ecma: 5, - warnings: false, - // Disabled because of an issue with Uglify breaking seemingly valid code: - // https://github.com/facebook/create-react-app/issues/2376 - // Pending further investigation: - // https://github.com/mishoo/UglifyJS2/issues/2011 - comparisons: false, - // Disabled because of an issue with Terser breaking valid code: - // https://github.com/facebook/create-react-app/issues/5250 - // Pending further investigation: - // https://github.com/terser-js/terser/issues/120 - inline: 2, - }, - mangle: { - safari10: true, - }, - // Added for profiling in devtools - keep_classnames: isEnvProductionProfile, - keep_fnames: isEnvProductionProfile, - output: { - ecma: 5, - comments: false, - // Turned on because emoji and regex is not minified properly using default - // https://github.com/facebook/create-react-app/issues/2488 - ascii_only: true, - }, - }, - sourceMap: shouldUseSourceMap, - }), - // This is only used in production mode - new OptimizeCSSAssetsPlugin({ - cssProcessorOptions: { - parser: safePostCssParser, - map: shouldUseSourceMap - ? { - // `inline: false` forces the sourcemap to be output into a - // separate file - inline: false, - // `annotation: true` appends the sourceMappingURL to the end of - // the css file, helping the browser find the sourcemap - annotation: true, - } - : false, - }, - cssProcessorPluginOptions: { - preset: ['default', { minifyFontValues: { removeQuotes: false } }], - }, - }), - ], - // Automatically split vendor and commons - // https://twitter.com/wSokra/status/969633336732905474 - // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366 - splitChunks: { - chunks: 'all', - name: false, - }, - // Keep the runtime chunk separated to enable long term caching - // https://twitter.com/wSokra/status/969679223278505985 - // https://github.com/facebook/create-react-app/issues/5358 - runtimeChunk: { - name: entrypoint => `runtime-${entrypoint.name}`, - }, - }, - resolve: { - // This allows you to set a fallback for where webpack should look for modules. - // We placed these paths second because we want `node_modules` to "win" - // if there are any conflicts. This matches Node resolution mechanism. - // https://github.com/facebook/create-react-app/issues/253 - modules: ['node_modules', paths.appNodeModules].concat( - modules.additionalModulePaths || [] - ), - // These are the reasonable defaults supported by the Node ecosystem. - // We also include JSX as a common component filename extension to support - // some tools, although we do not recommend using it, see: - // https://github.com/facebook/create-react-app/issues/290 - // `web` extension prefixes have been added for better support - // for React Native Web. - extensions: paths.moduleFileExtensions - .map(ext => `.${ext}`) - .filter(ext => useTypeScript || !ext.includes('ts')), - alias: { - // Support React Native Web - // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ - 'react-native': 'react-native-web', - // Allows for better profiling with ReactDevTools - ...(isEnvProductionProfile && { - 'react-dom$': 'react-dom/profiling', - 'scheduler/tracing': 'scheduler/tracing-profiling', - }), - ...(modules.webpackAliases || {}), - }, - plugins: [ - // Adds support for installing with Plug'n'Play, leading to faster installs and adding - // guards against forgotten dependencies and such. - PnpWebpackPlugin, - // Prevents users from importing files from outside of src/ (or node_modules/). - // This often causes confusion because we only process files within src/ with babel. - // To fix this, we prevent you from importing files out of src/ -- if you'd like to, - // please link the files into your node_modules/ and let module-resolution kick in. - // Make sure your source files are compiled, as they will not be processed in any way. - // new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), - ], - }, - resolveLoader: { - plugins: [ - // Also related to Plug'n'Play, but this time it tells webpack to load its loaders - // from the current package. - PnpWebpackPlugin.moduleLoader(module), - ], - }, - module: { - strictExportPresence: true, - rules: [ - // Disable require.ensure as it's not a standard language feature. - { parser: { requireEnsure: false } }, - - // First, run the linter. - // It's important to do this before Babel processes the JS. - { - test: /\.(js|mjs|jsx|ts|tsx)$/, - enforce: 'pre', - use: [ - { - options: { - cache: true, - formatter: require.resolve('react-dev-utils/eslintFormatter'), - eslintPath: require.resolve('eslint'), - resolvePluginsRelativeTo: __dirname, - // @remove-on-eject-begin - ignore: process.env.EXTEND_ESLINT === 'true', - baseConfig: (() => { - // We allow overriding the config only if the env variable is set - if (process.env.EXTEND_ESLINT === 'true') { - const eslintCli = new eslint.CLIEngine(); - let eslintConfig; - try { - eslintConfig = eslintCli.getConfigForFile( - paths.appIndexJs - ); - } catch (e) { - console.error(e); - process.exit(1); - } - return eslintConfig; - } else { - return { - extends: [require.resolve('eslint-config-react-app')], - }; - } - })(), - useEslintrc: false, - // @remove-on-eject-end - }, - loader: require.resolve('eslint-loader'), - }, - ], - include: paths.appSrc, - }, - { - // "oneOf" will traverse all following loaders until one will - // match the requirements. When no loader matches it will fall - // back to the "file" loader at the end of the loader list. - oneOf: [ - // "url" loader works like "file" loader except that it embeds assets - // smaller than specified limit in bytes as data URLs to avoid requests. - // A missing `test` is equivalent to a match. - { - test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/], - loader: require.resolve('url-loader'), - options: { - limit: imageInlineSizeLimit, - name: 'static/media/[name].[hash:8].[ext]', - }, - }, - // Process application JS with Babel. - // The preset includes JSX, Flow, TypeScript, and some ESnext features. - { - test: /\.(js|mjs|jsx|ts|tsx)$/, - include: includedSources, - loader: require.resolve('babel-loader'), - options: { - customize: require.resolve( - 'babel-preset-react-app/webpack-overrides' - ), - // @remove-on-eject-begin - babelrc: false, - configFile: false, - presets: [require.resolve('babel-preset-react-app')], - // Make sure we have a unique cache identifier, erring on the - // side of caution. - // We remove this when the user ejects because the default - // is sane and uses Babel options. Instead of options, we use - // the react-scripts and babel-preset-react-app versions. - cacheIdentifier: getCacheIdentifier( - isEnvProduction - ? 'production' - : isEnvDevelopment && 'development', - [ - 'babel-plugin-named-asset-import', - 'babel-preset-react-app', - 'react-dev-utils', - 'react-scripts', - ] - ), - // @remove-on-eject-end - plugins: [ - [ - require.resolve('babel-plugin-named-asset-import'), - { - loaderMap: { - svg: { - ReactComponent: - '@svgr/webpack?-svgo,+titleProp,+ref![path]', - }, - }, - }, - ], - ], - // This is a feature of `babel-loader` for webpack (not Babel itself). - // It enables caching results in ./node_modules/.cache/babel-loader/ - // directory for faster rebuilds. - cacheDirectory: true, - // See #6846 for context on why cacheCompression is disabled - cacheCompression: false, - compact: isEnvProduction, - }, - }, - // Process any JS outside of the app with Babel. - // Unlike the application JS, we only compile the standard ES features. - { - test: /\.(js|mjs)$/, - exclude: /@babel(?:\/|\\{1,2})runtime/, - loader: require.resolve('babel-loader'), - options: { - babelrc: false, - configFile: false, - compact: false, - presets: [ - [ - require.resolve('babel-preset-react-app/dependencies'), - { helpers: true }, - ], - ], - cacheDirectory: true, - // See #6846 for context on why cacheCompression is disabled - cacheCompression: false, - // @remove-on-eject-begin - cacheIdentifier: getCacheIdentifier( - isEnvProduction - ? 'production' - : isEnvDevelopment && 'development', - [ - 'babel-plugin-named-asset-import', - 'babel-preset-react-app', - 'react-dev-utils', - 'react-scripts', - ] - ), - // @remove-on-eject-end - // Babel sourcemaps are needed for debugging into node_modules - // code. Without the options below, debuggers like VSCode - // show incorrect code and set breakpoints on the wrong lines. - sourceMaps: shouldUseSourceMap, - inputSourceMap: shouldUseSourceMap, - }, - }, - // "postcss" loader applies autoprefixer to our CSS. - // "css" loader resolves paths in CSS and adds assets as dependencies. - // "style" loader turns CSS into JS modules that inject