0
# CLI Commands
1
2
Command-line interface for running customized create-react-app scripts with webpack and configuration overrides.
3
4
## Capabilities
5
6
### React App Rewired Command
7
8
Main CLI command that replaces react-scripts commands with override-enabled versions.
9
10
```bash { .api }
11
react-app-rewired <command> [options]
12
13
# Available commands:
14
# start - Run development server with overrides
15
# build - Run production build with overrides
16
# test - Run test suite with Jest overrides
17
# eject - Pass through to react-scripts eject
18
```
19
20
**Command Detection Logic:**
21
```javascript { .api }
22
// CLI finds command using this logic from bin/index.js
23
const scriptIndex = args.findIndex(
24
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
25
);
26
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
27
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
28
```
29
30
**Command Line Options:**
31
32
```bash { .api }
33
--scripts-version <package> # Use custom react-scripts package
34
--config-overrides <path> # Custom config-overrides location
35
```
36
37
**Usage Examples:**
38
39
```bash
40
# Standard usage
41
react-app-rewired start
42
react-app-rewired build
43
react-app-rewired test
44
45
# With custom scripts version
46
react-app-rewired start --scripts-version react-scripts-ts
47
react-app-rewired build --scripts-version react-scripts-ts
48
49
# With custom config-overrides location
50
react-app-rewired start --config-overrides ./custom/overrides.js
51
```
52
53
### Start Command
54
55
Runs the development server with webpack and dev server overrides applied.
56
57
```bash { .api }
58
react-app-rewired start [options]
59
```
60
61
**Process:**
62
1. Sets `NODE_ENV` to 'development' (if not already set)
63
2. Applies paths overrides to memory
64
3. Applies webpack configuration overrides
65
4. Applies dev server configuration overrides
66
5. Delegates to original `react-scripts start`
67
68
### Build Command
69
70
Runs the production build with webpack overrides applied.
71
72
```bash { .api }
73
react-app-rewired build [options]
74
```
75
76
**Process:**
77
1. Sets `NODE_ENV` to 'production'
78
2. Applies paths overrides to memory
79
3. Applies webpack configuration overrides
80
4. Delegates to original `react-scripts build`
81
82
### Test Command
83
84
Runs the test suite with Jest configuration overrides applied.
85
86
```bash { .api }
87
react-app-rewired test [options]
88
```
89
90
**Process:**
91
1. Sets `NODE_ENV` to 'test' (if not already set)
92
2. Applies paths overrides to memory
93
3. Applies Jest configuration overrides
94
4. Strips custom command line arguments from process.argv
95
5. Delegates to original `react-scripts test`
96
97
**Note:** The `--scripts-version` and `--config-overrides` arguments are automatically stripped before passing to the original test script to avoid rejection.
98
99
### Error Handling
100
101
The CLI handles various error scenarios with specific signal detection:
102
103
```javascript { .api }
104
// Signal handling for build interruption from bin/index.js
105
if (result.signal) {
106
if (result.signal === 'SIGKILL') {
107
console.log(
108
'The build failed because the process exited too early. ' +
109
'This probably means the system ran out of memory or someone called ' +
110
'`kill -9` on the process.'
111
);
112
} else if (result.signal === 'SIGTERM') {
113
console.log(
114
'The build failed because the process exited too early. ' +
115
'Someone might have called `kill` or `killall`, or the system could ' +
116
'be shutting down.'
117
);
118
}
119
process.exit(1);
120
}
121
122
// Unknown command handling
123
console.log('Unknown script "' + script + '".');
124
console.log('Perhaps you need to update react-scripts?');
125
console.log(
126
'See: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#updating-to-new-releases'
127
);
128
```
129
130
### Environment Variables
131
132
```javascript { .api }
133
// Supported environment variables
134
REACT_SCRIPTS_VERSION // Override react-scripts package name
135
NODE_ENV // Set by commands (development/production/test)
136
```
137
138
### Package.json Configuration
139
140
```json { .api }
141
{
142
"config-overrides-path": "node_modules/some-preconfigured-rewire"
143
}
144
```
145
146
Custom path for config-overrides.js file, useful for using third-party override configurations.