Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit f06d07d

Browse files
looseendNargonath
authored andcommitted
feat: handle react-scripts 2.1.1 new webpack format (#20)
* react-scripts > v2.1.1 don't have a webpack.config.dev * make isEjected work of config/paths.js
1 parent 1bb8e60 commit f06d07d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

scripts/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,22 @@ const {
1111
flags: { buildPath, publicPath, reactScriptsVersion, verbose },
1212
} = require('../utils/cliHandler');
1313
const { getReactScriptsVersion, isEjected } = require('../utils');
14+
15+
const { major, minor, patch } = getReactScriptsVersion(reactScriptsVersion);
16+
1417
const paths = isEjected ? importCwd('./config/paths') : importCwd('react-scripts/config/paths');
1518
const webpack = importCwd('webpack');
16-
const config = isEjected
17-
? importCwd('./config/webpack.config.dev')
18-
: importCwd('react-scripts/config/webpack.config.dev');
19+
20+
const config = (major >= 2 && minor >= 1 && patch >= 2) ?
21+
(isEjected
22+
? importCwd('./config/webpack.config')
23+
: importCwd('react-scripts/config/webpack.config'))('development')
24+
:
25+
isEjected
26+
? importCwd('./config/webpack.config.dev')
27+
: importCwd('react-scripts/config/webpack.config.dev');
28+
29+
1930
const HtmlWebpackPlugin = importCwd('html-webpack-plugin');
2031
const InterpolateHtmlPlugin = importCwd('react-dev-utils/InterpolateHtmlPlugin');
2132
const getClientEnvironment = isEjected
@@ -50,8 +61,6 @@ config.output.filename = `js/bundle.js`;
5061
config.output.chunkFilename = `js/[name].chunk.js`;
5162

5263
// update media path destination
53-
const { major, minor, patch } = getReactScriptsVersion(reactScriptsVersion);
54-
5564
if (major >= 2) {
5665
const oneOfIndex = minor >= 1 || patch >= 4 ? 2 : 3;
5766
config.module.rules[oneOfIndex].oneOf[0].options.name = `media/[name].[hash:8].[ext]`;

utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const DEFAULT_VERSION = {
1111
patch: 4,
1212
};
1313

14-
exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/webpack.config.dev.js'));
14+
exports.isEjected = fs.pathExistsSync(path.join(process.cwd(), 'config/paths.js'))
1515

1616
exports.getReactScriptsVersion = function getReactScriptsVersion(cliVersion) {
1717
if (cliVersion) {

0 commit comments

Comments
 (0)