Skip to content

Commit 4ff112b

Browse files
committed
separate dev config and prod config, cleanup code on eject, ship prod config only on release and dev-pack
1 parent d071aa0 commit 4ff112b

File tree

16 files changed

+170
-84
lines changed

16 files changed

+170
-84
lines changed

config/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = function(name, stage) {
11+
if(stage){
12+
return require('./'+name+'.'+stage);
13+
}
14+
15+
var isInCreateReactAppSource = (
16+
process.argv.some(arg => arg.indexOf('--debug-template') > -1)
17+
);
18+
if (isInCreateReactAppSource) {
19+
return require('./'+name+'.dev');
20+
}else {
21+
return require('./'+name+'.prod');
22+
}
23+
}

config/index.prod.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = function(name) {
11+
return require('./'+name+'.prod');
12+
}

config/paths.dev.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
var path = require('path');
11+
12+
function resolve(relativePath) {
13+
return path.resolve(__dirname, relativePath);
14+
}
15+
16+
// create-react-app development: we're in ./config/
17+
module.exports = {
18+
appBuild: resolve('../build'),
19+
appHtml: resolve('../template/index.html'),
20+
appFavicon: resolve('../template/favicon.ico'),
21+
appPackageJson: resolve('../package.json'),
22+
appSrc: resolve('../template/src'),
23+
appNodeModules: resolve('../node_modules'),
24+
ownNodeModules: resolve('../node_modules')
25+
};

config/paths.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

config/paths.prod.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
var path = require('path');
11+
12+
function resolve(relativePath) {
13+
return path.resolve(__dirname, relativePath);
14+
}
15+
16+
module.exports = {
17+
appBuild: resolve('../build'),
18+
appHtml: resolve('../index.html'),
19+
appFavicon: resolve('../favicon.ico'),
20+
appPackageJson: resolve('../package.json'),
21+
appSrc: resolve('../src'),
22+
appNodeModules: resolve('../node_modules'),
23+
ownNodeModules: resolve('../node_modules')
24+
};
25+
26+
// Dead code on eject: start
27+
// before eject: we're in ./node_modules/react-scripts/config/
28+
module.exports = {
29+
appBuild: resolve('../../../build'),
30+
appHtml: resolve('../../../index.html'),
31+
appFavicon: resolve('../../../favicon.ico'),
32+
appPackageJson: resolve('../../../package.json'),
33+
appSrc: resolve('../../../src'),
34+
appNodeModules: resolve('../..'),
35+
// this is empty with npm3 but node resolution searches higher anyway:
36+
ownNodeModules: resolve('../node_modules')
37+
};
38+
// Dead code on eject: end

config/webpack.config.dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var path = require('path');
1111
var autoprefixer = require('autoprefixer');
1212
var webpack = require('webpack');
1313
var HtmlWebpackPlugin = require('html-webpack-plugin');
14-
var paths = require('./paths');
14+
var paths = require('./')('paths');
1515

1616
module.exports = {
1717
devtool: 'eval',
@@ -48,7 +48,7 @@ module.exports = {
4848
test: /\.js$/,
4949
include: paths.appSrc,
5050
loader: 'babel',
51-
query: require('./babel.dev')
51+
query: require('./')('babel')
5252
},
5353
{
5454
test: /\.css$/,

config/webpack.config.prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var webpack = require('webpack');
1313
var HtmlWebpackPlugin = require('html-webpack-plugin');
1414
var ExtractTextPlugin = require('extract-text-webpack-plugin');
1515
var url = require('url');
16-
var paths = require('./paths');
16+
var paths = require('./')('paths');
1717

1818
var homepagePath = require(paths.appPackageJson).homepage;
1919
var publicPath = homepagePath ? url.parse(homepagePath).pathname : '/';
@@ -55,7 +55,7 @@ module.exports = {
5555
test: /\.js$/,
5656
include: paths.appSrc,
5757
loader: 'babel',
58-
query: require('./babel.prod')
58+
query: require('./')('babel')
5959
},
6060
{
6161
test: /\.css$/,

global-cli/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var argv = require('minimist')(process.argv.slice(2));
5050
* Example of valid values:
5151
* - a specific npm version: "0.22.0-rc1"
5252
* - a .tgz archive from any npm repo: "https://registry.npmjs.org/react-scripts/-/react-scripts-0.20.0.tgz"
53-
* - a package prepared with `npm pack`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz"
53+
* - a package prepared with `tasks/pack.sh`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz"
5454
*/
5555
var commands = argv._;
5656
if (commands.length === 0) {

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
"scripts": {
1414
"start": "node scripts/start.js --debug-template",
1515
"build": "node scripts/build.js --debug-template",
16-
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\"",
16+
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`tasks/pack.sh`\"",
1717
"test": "tasks/e2e.sh"
1818
},
1919
"files": [
2020
"LICENSE",
2121
"PATENTS",
2222
"bin",
23-
"config",
23+
"config/flow",
24+
"config/*.prod.js",
25+
"!config/index.prod.js",
26+
"config/eslint.js",
27+
"config/index.js",
28+
"config/polyfills.js",
2429
"scripts",
2530
"template"
2631
],

scripts/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var filesize = require('filesize');
1414
var gzipSize = require('gzip-size');
1515
var rimrafSync = require('rimraf').sync;
1616
var webpack = require('webpack');
17-
var config = require('../config/webpack.config.prod');
18-
var paths = require('../config/paths');
17+
var config = require('../config')('webpack.config', 'prod');
18+
var paths = require('../config')('paths');
1919

2020
// Remove all content but keep the directory so that
2121
// if you're in it, you don't end up in Trash

0 commit comments

Comments
 (0)