From d722abb03ea1d1fd1adf27e3d82307052172e090 Mon Sep 17 00:00:00 2001 From: John Singleton Date: Mon, 7 Jan 2019 10:59:38 +0000 Subject: [PATCH 1/5] react-scripts > v2.1.1 don't have a webpack.config.dev webpack.config exposes config as a function which needs to be called with an env name. --- scripts/index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/index.js b/scripts/index.js index d6299ce..864c3b1 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -11,11 +11,22 @@ const { flags: { buildPath, publicPath, reactScriptsVersion, verbose }, } = require('../utils/cliHandler'); const { getReactScriptsVersion, isEjected } = require('../utils'); + +const { major, minor, patch } = getReactScriptsVersion(reactScriptsVersion); + const paths = isEjected ? importCwd('./config/paths') : importCwd('react-scripts/config/paths'); const webpack = importCwd('webpack'); -const config = isEjected - ? importCwd('./config/webpack.config.dev') - : importCwd('react-scripts/config/webpack.config.dev'); + +const config = (major >= 2 && minor >= 1 && patch >= 2) ? + (isEjected + ? importCwd('./config/webpack.config') + : importCwd('react-scripts/config/webpack.config'))('development') + : + isEjected + ? importCwd('./config/webpack.config.dev') + : importCwd('react-scripts/config/webpack.config.dev'); + + const HtmlWebpackPlugin = importCwd('html-webpack-plugin'); const InterpolateHtmlPlugin = importCwd('react-dev-utils/InterpolateHtmlPlugin'); const getClientEnvironment = isEjected @@ -50,8 +61,6 @@ config.output.filename = `js/bundle.js`; config.output.chunkFilename = `js/[name].chunk.js`; // update media path destination -const { major, minor, patch } = getReactScriptsVersion(reactScriptsVersion); - if (major >= 2) { const oneOfIndex = minor >= 1 || patch >= 4 ? 2 : 3; config.module.rules[oneOfIndex].oneOf[0].options.name = `media/[name].[hash:8].[ext]`; From 0c504fc07c892b01013dd1f50f6999f93e65bd52 Mon Sep 17 00:00:00 2001 From: John Singleton Date: Mon, 7 Jan 2019 12:40:00 +0000 Subject: [PATCH 2/5] make isEjected workk of config/paths.js Clean the version string before passing to semver, as ^ and ~ prefixes break the parsing --- utils/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/index.js b/utils/index.js index 9b116d6..d7f6774 100644 --- a/utils/index.js +++ b/utils/index.js @@ -11,7 +11,7 @@ const DEFAULT_VERSION = { patch: 4, }; -exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/webpack.config.dev.js')); +exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/paths.js')) exports.getReactScriptsVersion = function getReactScriptsVersion(cliVersion) { if (cliVersion) { @@ -29,10 +29,11 @@ exports.getReactScriptsVersion = function getReactScriptsVersion(cliVersion) { } const { dependencies } = packageJson; + const reactScriptsVersionString = /^[~^]?([.0-9]+)$/.exec(dependencies['react-scripts'])[1]; const versions = { - major: Number(semver.major(dependencies['react-scripts'])), - minor: Number(semver.minor(dependencies['react-scripts'])), - patch: Number(semver.patch(dependencies['react-scripts'])), + major: Number(semver.major(reactScriptsVersionString)), + minor: Number(semver.minor(reactScriptsVersionString)), + patch: Number(semver.patch(reactScriptsVersionString)), }; return versions; }; From 1d56f1c92f92f2552f68a3e80a676f976873e8a7 Mon Sep 17 00:00:00 2001 From: John Singleton Date: Thu, 10 Jan 2019 14:45:26 +0000 Subject: [PATCH 3/5] Back out get version changes --- utils/index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/utils/index.js b/utils/index.js index d7f6774..b72a133 100644 --- a/utils/index.js +++ b/utils/index.js @@ -8,17 +8,17 @@ const path = require('path'); const DEFAULT_VERSION = { major: 2, minor: 0, - patch: 4, + patch: 4 }; exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/paths.js')) -exports.getReactScriptsVersion = function getReactScriptsVersion(cliVersion) { +exports.getReactScriptsVersion = function (cliVersion) { if (cliVersion) { const versions = { major: Number(semver.major(cliVersion)), minor: Number(semver.minor(cliVersion)), - patch: Number(semver.patch(cliVersion)), + patch: Number(semver.patch(cliVersion)) }; return versions; } @@ -29,11 +29,10 @@ exports.getReactScriptsVersion = function getReactScriptsVersion(cliVersion) { } const { dependencies } = packageJson; - const reactScriptsVersionString = /^[~^]?([.0-9]+)$/.exec(dependencies['react-scripts'])[1]; const versions = { - major: Number(semver.major(reactScriptsVersionString)), - minor: Number(semver.minor(reactScriptsVersionString)), - patch: Number(semver.patch(reactScriptsVersionString)), + major: Number(semver.major(dependencies['react-scripts'])), + minor: Number(semver.minor(dependencies['react-scripts'])), + patch: Number(semver.patch(dependencies['react-scripts'])) }; return versions; }; From bfbe83af89733e01d42134de45091d742b3f3f3f Mon Sep 17 00:00:00 2001 From: John Singleton Date: Thu, 10 Jan 2019 14:46:09 +0000 Subject: [PATCH 4/5] Back out get version changes --- utils/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/index.js b/utils/index.js index b72a133..465f2c7 100644 --- a/utils/index.js +++ b/utils/index.js @@ -8,7 +8,7 @@ const path = require('path'); const DEFAULT_VERSION = { major: 2, minor: 0, - patch: 4 + patch: 4, }; exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/paths.js')) @@ -18,7 +18,7 @@ exports.getReactScriptsVersion = function (cliVersion) { const versions = { major: Number(semver.major(cliVersion)), minor: Number(semver.minor(cliVersion)), - patch: Number(semver.patch(cliVersion)) + patch: Number(semver.patch(cliVersion)), }; return versions; } @@ -32,7 +32,7 @@ exports.getReactScriptsVersion = function (cliVersion) { const versions = { major: Number(semver.major(dependencies['react-scripts'])), minor: Number(semver.minor(dependencies['react-scripts'])), - patch: Number(semver.patch(dependencies['react-scripts'])) + patch: Number(semver.patch(dependencies['react-scripts'])), }; return versions; }; From 74410d57aad1ba12abfe89679df3c6f8fb89cda8 Mon Sep 17 00:00:00 2001 From: John Singleton Date: Thu, 10 Jan 2019 14:46:42 +0000 Subject: [PATCH 5/5] Back out get version changes --- utils/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/index.js b/utils/index.js index 465f2c7..ca20ad5 100644 --- a/utils/index.js +++ b/utils/index.js @@ -13,7 +13,7 @@ const DEFAULT_VERSION = { exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/paths.js')) -exports.getReactScriptsVersion = function (cliVersion) { +exports.getReactScriptsVersion = function getReactScriptsVersion(cliVersion) { if (cliVersion) { const versions = { major: Number(semver.major(cliVersion)),