1
1
const fs = require ( 'fs' ) ;
2
2
const path = require ( 'path' ) ;
3
3
4
- const CREATE_REACT_APP_WEBPACK_CONFIG = 'react-scripts/config/webpack.config.dev' ;
4
+ // react-scripts <= 2.1.1
5
+ const CREATE_REACT_APP_WEBPACK_CONFIG_OLD = 'react-scripts/config/webpack.config.dev' ;
6
+ // react-scripts > 2.1.1
7
+ const CREATE_REACT_APP_WEBPACK_CONFIG = 'react-scripts/config/webpack.config' ;
5
8
const USER_WEBPACK_CONFIG_NAMES = [ 'webpack.config.js' , 'webpackfile.js' ] ;
6
9
7
10
const absolutize = filePath => path . resolve ( process . cwd ( ) , filePath ) ;
@@ -17,14 +20,19 @@ const absolutize = filePath => path.resolve(process.cwd(), filePath);
17
20
module . exports = function findUserWebpackConfig ( resolve ) {
18
21
resolve = resolve || require . resolve ;
19
22
try {
20
- // Create React App
21
- return resolve ( CREATE_REACT_APP_WEBPACK_CONFIG ) ;
23
+ // Create React App <= 2.1.1
24
+ return resolve ( CREATE_REACT_APP_WEBPACK_CONFIG_OLD ) ;
22
25
} catch ( err ) {
23
- // Check in the root folder
24
- for ( const configFile of USER_WEBPACK_CONFIG_NAMES ) {
25
- const absoluteConfigFile = absolutize ( configFile ) ;
26
- if ( fs . existsSync ( absoluteConfigFile ) ) {
27
- return absoluteConfigFile ;
26
+ try {
27
+ // Create React App > 2.1.1
28
+ return resolve ( CREATE_REACT_APP_WEBPACK_CONFIG ) ;
29
+ } catch ( err ) {
30
+ // Check in the root folder
31
+ for ( const configFile of USER_WEBPACK_CONFIG_NAMES ) {
32
+ const absoluteConfigFile = absolutize ( configFile ) ;
33
+ if ( fs . existsSync ( absoluteConfigFile ) ) {
34
+ return absoluteConfigFile ;
35
+ }
28
36
}
29
37
}
30
38
}
0 commit comments