Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-app-rewired support react-scripts more than 2.1.2 version #344

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions packages/react-app-rewired/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ process.env.NODE_ENV = 'production';

const paths = require('./utils/paths');
const overrides = require('../config-overrides');
const webpackConfigPath = paths.scriptVersion + "/config/webpack.config.prod";
const scriptPkg = require(paths.scriptVersion + "/package.json");

const isOldScript = !(scriptPkg && scriptPkg.version >= '2.1.2');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt this version comparison works for all semver features 😕

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const webpackConfigPath = paths.scriptVersion + isOldScript ? "/config/webpack.config.prod" : "/config/webpack.config";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather use a try/catch block and require.resolve to detect which config file is available

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it doesn't work :(

brackets are missing. should be

const webpackConfigPath = paths.scriptVersion + (isOldScript ? "/config/webpack.config.prod" : "/config/webpack.config");

or like this

const webpackConfigPathSuffix = isOldScript ? ".prod" : "";
const webpackConfigPath = paths.scriptVersion + "/config/webpack.config" + webpackConfigPathSuffix;

and the same for start


// load original config
const webpackConfig = require(webpackConfigPath);
// override config in memory
require.cache[require.resolve(webpackConfigPath)].exports =
overrides.webpack(webpackConfig, process.env.NODE_ENV);
isOldScript ? overrides.webpack(webpackConfig, process.env.NODE_ENV) : (env) => overrides.webpack(webpackConfig(env), env);
// run original script
require(paths.scriptVersion + '/scripts/build');
8 changes: 6 additions & 2 deletions packages/react-app-rewired/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ process.env.NODE_ENV = process.env.NODE_ENV || "development";

const paths = require("./utils/paths");
const overrides = require('../config-overrides');
const webpackConfigPath = paths.scriptVersion + "/config/webpack.config.dev";
const scriptPkg = require(paths.scriptVersion + "/package.json");

const isOldScript = !(scriptPkg && scriptPkg.version >= '2.1.2');

const webpackConfigPath = paths.scriptVersion + isOldScript ? "/config/webpack.config.dev" : "/config/webpack.config";
const devServerConfigPath = paths.scriptVersion + "/config/webpackDevServer.config.js";

// load original configs
const webpackConfig = require(webpackConfigPath);
const devServerConfig = require(devServerConfigPath);
// override config in memory
require.cache[require.resolve(webpackConfigPath)].exports =
overrides.webpack(webpackConfig, process.env.NODE_ENV);
isOldScript ? overrides.webpack(webpackConfig, process.env.NODE_ENV) : (env) => overrides.webpack(webpackConfig(env), env);

require.cache[require.resolve(devServerConfigPath)].exports =
overrides.devServer(devServerConfig, process.env.NODE_ENV);
Expand Down