Skip to content

Commit be18c81

Browse files
committed
* 'master' of https://github.com/facebookincubator/create-react-app: 0.3.0-alpha Update some deps Document configuration and build process (facebook#362) # Conflicts: # config/webpack.config.dev.js
2 parents 38c9976 + db4c6f6 commit be18c81

File tree

9 files changed

+210
-24
lines changed

9 files changed

+210
-24
lines changed

config/babel.dev.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@
88
*/
99

1010
module.exports = {
11+
// Don't try to find .babelrc because we want to force this configuration.
1112
babelrc: false,
13+
// This is a feature of `babel-loader` for webpack (not Babel itself).
14+
// It enables caching results in OS temporary directory for faster rebuilds.
1215
cacheDirectory: true,
1316
presets: [
17+
// let, const, destructuring, classes, modules
1418
require.resolve('babel-preset-es2015'),
19+
// exponentiation
1520
require.resolve('babel-preset-es2016'),
21+
// JSX, Flow
1622
require.resolve('babel-preset-react')
1723
],
1824
plugins: [
25+
// function x(a, b, c,) { }
1926
require.resolve('babel-plugin-syntax-trailing-function-commas'),
27+
// await fetch()
2028
require.resolve('babel-plugin-syntax-async-functions'),
29+
// class { handleClick = () => { } }
2130
require.resolve('babel-plugin-transform-class-properties'),
31+
// { ...todo, completed: true }
2232
require.resolve('babel-plugin-transform-object-rest-spread'),
33+
// function* () { yield 42; yield 43; }
2334
require.resolve('babel-plugin-transform-regenerator'),
35+
// Polyfills the runtime needed for async/await and generators
2436
[require.resolve('babel-plugin-transform-runtime'), {
2537
helpers: false,
2638
polyfill: false,

config/babel.prod.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,34 @@
88
*/
99

1010
module.exports = {
11+
// Don't try to find .babelrc because we want to force this configuration.
1112
babelrc: false,
1213
presets: [
14+
// let, const, destructuring, classes, modules
1315
require.resolve('babel-preset-es2015'),
16+
// exponentiation
1417
require.resolve('babel-preset-es2016'),
18+
// JSX, Flow
1519
require.resolve('babel-preset-react')
1620
],
1721
plugins: [
22+
// function x(a, b, c,) { }
1823
require.resolve('babel-plugin-syntax-trailing-function-commas'),
24+
// await fetch()
1925
require.resolve('babel-plugin-syntax-async-functions'),
26+
// class { handleClick = () => { } }
2027
require.resolve('babel-plugin-transform-class-properties'),
28+
// { ...todo, completed: true }
2129
require.resolve('babel-plugin-transform-object-rest-spread'),
22-
require.resolve('babel-plugin-transform-react-constant-elements'),
30+
// function* () { yield 42; yield 43; }
2331
require.resolve('babel-plugin-transform-regenerator'),
32+
// Polyfills the runtime needed for async/await and generators
2433
[require.resolve('babel-plugin-transform-runtime'), {
2534
helpers: false,
2635
polyfill: false,
2736
regenerator: true
28-
}]
37+
}],
38+
// Optimization: hoist JSX that never changes out of render()
39+
require.resolve('babel-plugin-transform-react-constant-elements')
2940
]
3041
};

config/env.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10+
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
11+
// injected into the application via DefinePlugin in Webpack configuration.
12+
1013
var REACT_APP = /^REACT_APP_/i;
1114
var NODE_ENV = JSON.stringify(process.env.NODE_ENV || 'development');
1215

config/polyfills.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ if (typeof Promise === 'undefined') {
66
window.Promise = require('promise/lib/es6-extensions.js');
77
}
88

9+
// fetch() polyfill for making API calls.
910
require('whatwg-fetch');

config/webpack.config.dev.js

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,57 @@ var WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeMo
1717
var paths = require('./paths');
1818
var env = require('./env');
1919

20+
// This is the development configuration.
21+
// It is focused on developer experience and fast rebuilds.
22+
// The production configuration is different and lives in a separate file.
2023
module.exports = {
24+
// This makes the bundle appear split into separate modules in the devtools.
25+
// We don't use source maps here because they can be confusing:
26+
// https://github.com/facebookincubator/create-react-app/issues/343#issuecomment-237241875
27+
// You may want 'cheap-module-source-map' instead if you prefer source maps.
2128
devtool: 'eval',
29+
// These are the "entry points" to our application.
30+
// This means they will be the "root" imports that are included in JS bundle.
31+
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
2232
entry: [
33+
// Include WebpackDevServer client. It connects to WebpackDevServer via
34+
// sockets and waits for recompile notifications. When WebpackDevServer
35+
// recompiles, it sends a message to the client by socket. If only CSS
36+
// was changed, the app reload just the CSS. Otherwise, it will refresh.
37+
// The "?/" bit at the end tells the client to look for the socket at
38+
// the root path, i.e. /sockjs-node/. Otherwise visiting a client-side
39+
// route like /todos/42 would make it wrongly request /todos/42/sockjs-node.
40+
// The socket server is a part of WebpackDevServer which we are using.
41+
// The /sockjs-node/ path I'm referring to is hardcoded in WebpackDevServer.
2342
require.resolve('webpack-dev-server/client') + '?/',
43+
// Include Webpack hot module replacement runtime. Webpack is pretty
44+
// low-level so we need to put all the pieces together. The runtime listens
45+
// to the events received by the client above, and applies updates (such as
46+
// new CSS) to the running application.
2447
require.resolve('webpack/hot/dev-server'),
48+
// We ship a few polyfills by default.
2549
require.resolve('./polyfills'),
50+
// Finally, this is your app's code:
2651
path.join(paths.appSrc, 'index')
52+
// We include the app code last so that if there is a runtime error during
53+
// initialization, it doesn't blow up the WebpackDevServer client, and
54+
// changing JS code would still trigger a refresh.
2755
],
2856
output: {
2957
// Next line is not used in dev but WebpackDevServer crashes without it:
3058
path: paths.appBuild,
59+
// Add /* filename */ comments to generated require()s in the output.
3160
pathinfo: true,
61+
// This does not produce a real file. It's just the virtual path that is
62+
// served by WebpackDevServer in development. This is the JS bundle
63+
// containing code from all our entry points, and the Webpack runtime.
3264
filename: 'static/js/bundle.js',
65+
// In development, we always serve from the root. This makes config easier.
3366
publicPath: '/'
3467
},
3568
resolve: {
69+
// These are the reasonable defaults supported by the Node ecosystem.
70+
// We also include .jsx extension in order to warn with CheckFilenamePlugin.
3671
extensions: ['.jsx', '.js', '.json', ''],
3772
alias: {
3873
// This `alias` section can be safely removed after ejection.
@@ -46,11 +81,16 @@ module.exports = {
4681
'babel-runtime/regenerator': require.resolve('babel-runtime/regenerator')
4782
}
4883
},
84+
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
85+
// directory of `react-scripts` itself rather than the project directory.
86+
// You can remove this after ejecting.
4987
resolveLoader: {
5088
root: paths.ownNodeModules,
5189
moduleTemplates: ['*-loader']
5290
},
5391
module: {
92+
// First, run the linter.
93+
// It's important to do this before Babel processes the JS.
5494
preLoaders: [
5595
{
5696
test: /\.js$/,
@@ -59,22 +99,33 @@ module.exports = {
5999
}
60100
],
61101
loaders: [
102+
// Process JS with Babel.
62103
{
63104
test: /\.js$/,
64105
include: paths.appSrc,
65106
loader: 'babel',
66107
query: require('./babel.dev')
67108
},
109+
// "postcss" loader applies autoprefixer to our CSS.
110+
// "css" loader resolves paths in CSS and adds assets as dependencies.
111+
// "style" loader turns CSS into JS modules that inject <style> tags.
112+
// In production, we use a plugin to extract that CSS to a file, but
113+
// in development "style" loader enables hot editing of CSS.
68114
{
69115
test: /\.css$/,
70116
include: [paths.appSrc, paths.appNodeModules],
71117
loader: 'style!css!postcss'
72118
},
119+
// JSON is not enabled by default in Webpack but both Node and Browserify
120+
// allow it implicitly so we also enable it.
73121
{
74122
test: /\.json$/,
75123
include: [paths.appSrc, paths.appNodeModules],
76124
loader: 'json'
77125
},
126+
// "file" loader makes sure those assets get served by WebpackDevServer.
127+
// When you `import` an asset, you get its (virtual) filename.
128+
// In production, they would get copied to the `build` folder.
78129
{
79130
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/,
80131
include: [paths.appSrc, paths.appNodeModules],
@@ -83,6 +134,8 @@ module.exports = {
83134
name: 'static/media/[name].[ext]'
84135
}
85136
},
137+
// "url" loader works just like "file" loader but it also embeds
138+
// assets smaller than specified size as data URLs to avoid requests.
86139
{
87140
test: /\.(mp4|webm)(\?.*)?$/,
88141
include: [paths.appSrc, paths.appNodeModules],
@@ -94,38 +147,53 @@ module.exports = {
94147
}
95148
]
96149
},
150+
// Point ESLint to our predefined config.
97151
eslint: {
98152
configFile: path.join(__dirname, 'eslint.js'),
99153
useEslintrc: false
100154
},
155+
// We use PostCSS for autoprefixing only.
101156
postcss: function() {
102157
return [
103158
autoprefixer({
104159
browsers: [
105160
'>1%',
106161
'last 4 versions',
107162
'Firefox ESR',
108-
'not ie < 9',
163+
'not ie < 9', // React doesn't support IE8 anyway
109164
]
110165
}),
111166
];
112167
},
113168
plugins: [
169+
// Generates an `index.html` file with the <script> injected.
114170
new HtmlWebpackPlugin({
115171
inject: true,
116172
template: paths.appHtml,
117173
favicon: paths.appFavicon,
118174
}),
175+
// Makes some environment variables available to the JS code, for example:
176+
// if (process.env.NODE_ENV === 'development') { ... }. See `env.js`.
119177
new webpack.DefinePlugin(env),
120-
// Note: only CSS is currently hot reloaded
178+
// This is necessary to emit hot updates (currently CSS only):
121179
new webpack.HotModuleReplacementPlugin(),
180+
// Watcher doesn't work well if you mistype casing in a path so we use
181+
// a plugin that prints an error when you attempt to do this.
182+
// See https://github.com/facebookincubator/create-react-app/issues/240
122183
new CaseSensitivePathsPlugin(),
184+
<<<<<<< HEAD
123185
new CheckFilenamePlugin({
124186
regex: /\.jsx$/,
125187
error: function(filename) {
126188
return 'Module load aborted: .jsx extensions are not allowed, use .js extensions only. See create-react-app/issues/290 for more info.\n\tFor: ' + filename;
127189
}
128190
}),
191+
=======
192+
// If you require a missing module and then `npm install` it, you still have
193+
// to restart the development server for Webpack to discover it. This plugin
194+
// makes the discovery automatic so you don't have to restart.
195+
// See https://github.com/facebookincubator/create-react-app/issues/186
196+
>>>>>>> master
129197
new WatchMissingNodeModulesPlugin(paths.appNodeModules)
130198
]
131199
};

0 commit comments

Comments
 (0)