Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]`;
Expand Down
2 changes: 1 addition & 1 deletion utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down