Skip to content

Commit

Permalink
Load paths config before webpack config. (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
benwiley4000 committed Apr 29, 2020
1 parent 3602879 commit b6f727d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ const { scriptVersion } = require('./utils/paths');
const overrides = require('../config-overrides');
const scriptPkg = require(`${scriptVersion}/package.json`);

const pathsConfigPath = `${scriptVersion}/config/paths.js`;
const pathsConfig = require(pathsConfigPath);

// override paths in memory
require.cache[require.resolve(pathsConfigPath)].exports =
overrides.paths(pathsConfig, process.env.NODE_ENV);

// CRA 2.1.2 switched to using a webpack config factory
// https://github.com/facebook/create-react-app/pull/5722
// https://github.com/facebook/create-react-app/releases/tag/v2.1.2
Expand All @@ -19,12 +26,5 @@ require.cache[require.resolve(webpackConfigPath)].exports = isWebpackFactory
? (env) => overrides.webpack(webpackConfig(env), env)
: overrides.webpack(webpackConfig, process.env.NODE_ENV);

const pathsConfigPath = `${scriptVersion}/config/paths.js`;
const pathsConfig = require(pathsConfigPath);

// override paths in memory
require.cache[require.resolve(pathsConfigPath)].exports =
overrides.paths(pathsConfig, process.env.NODE_ENV);

// run original script
require(`${scriptVersion}/scripts/build`);
14 changes: 7 additions & 7 deletions scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ const { scriptVersion } = require('./utils/paths');
const overrides = require('../config-overrides');
const scriptPkg = require(`${scriptVersion}/package.json`);

const pathsConfigPath = `${scriptVersion}/config/paths.js`;
const pathsConfig = require(pathsConfigPath);

// override paths in memory
require.cache[require.resolve(pathsConfigPath)].exports =
overrides.paths(pathsConfig, process.env.NODE_ENV);

// CRA 2.1.2 switched to using a webpack config factory
// https://github.com/facebook/create-react-app/pull/5722
// https://github.com/facebook/create-react-app/releases/tag/v2.1.2
Expand All @@ -24,12 +31,5 @@ require.cache[require.resolve(webpackConfigPath)].exports = isWebpackFactory
require.cache[require.resolve(devServerConfigPath)].exports =
overrides.devServer(devServerConfig, process.env.NODE_ENV);

const pathsConfigPath = `${scriptVersion}/config/paths.js`;
const pathsConfig = require(pathsConfigPath);

// override paths in memory
require.cache[require.resolve(pathsConfigPath)].exports =
overrides.paths(pathsConfig, process.env.NODE_ENV);

// run original script
require(`${scriptVersion}/scripts/start`);

0 comments on commit b6f727d

Please sign in to comment.