Tweak the create-react-app webpack config(s) without using 'eject' and without creating a fork of the react-scripts
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Command-line interface for running customized create-react-app scripts with webpack and configuration overrides.
Main CLI command that replaces react-scripts commands with override-enabled versions.
react-app-rewired <command> [options]
# Available commands:
# start - Run development server with overrides
# build - Run production build with overrides
# test - Run test suite with Jest overrides
# eject - Pass through to react-scripts ejectCommand Detection Logic:
// CLI finds command using this logic from bin/index.js
const scriptIndex = args.findIndex(
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
);
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];Command Line Options:
--scripts-version <package> # Use custom react-scripts package
--config-overrides <path> # Custom config-overrides locationUsage Examples:
# Standard usage
react-app-rewired start
react-app-rewired build
react-app-rewired test
# With custom scripts version
react-app-rewired start --scripts-version react-scripts-ts
react-app-rewired build --scripts-version react-scripts-ts
# With custom config-overrides location
react-app-rewired start --config-overrides ./custom/overrides.jsRuns the development server with webpack and dev server overrides applied.
react-app-rewired start [options]Process:
NODE_ENV to 'development' (if not already set)react-scripts startRuns the production build with webpack overrides applied.
react-app-rewired build [options]Process:
NODE_ENV to 'production'react-scripts buildRuns the test suite with Jest configuration overrides applied.
react-app-rewired test [options]Process:
NODE_ENV to 'test' (if not already set)react-scripts testNote: The --scripts-version and --config-overrides arguments are automatically stripped before passing to the original test script to avoid rejection.
The CLI handles various error scenarios with specific signal detection:
// Signal handling for build interruption from bin/index.js
if (result.signal) {
if (result.signal === 'SIGKILL') {
console.log(
'The build failed because the process exited too early. ' +
'This probably means the system ran out of memory or someone called ' +
'`kill -9` on the process.'
);
} else if (result.signal === 'SIGTERM') {
console.log(
'The build failed because the process exited too early. ' +
'Someone might have called `kill` or `killall`, or the system could ' +
'be shutting down.'
);
}
process.exit(1);
}
// Unknown command handling
console.log('Unknown script "' + script + '".');
console.log('Perhaps you need to update react-scripts?');
console.log(
'See: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#updating-to-new-releases'
);// Supported environment variables
REACT_SCRIPTS_VERSION // Override react-scripts package name
NODE_ENV // Set by commands (development/production/test){
"config-overrides-path": "node_modules/some-preconfigured-rewire"
}Custom path for config-overrides.js file, useful for using third-party override configurations.
Install with Tessl CLI
npx tessl i tessl/npm-react-app-rewired