Skip to content

Commit cca16df

Browse files
TimerDaniel Figueiredo
authored andcommitted
Upgrade webpack (facebook#1291)
* Upgrade webpack * Address more webpack v2 ... * Update html-webpack-plugin * Remove LoaderOptionsPlugin from dev config * ExtractTextPlugin still uses webpack 1 syntax ... and doesn't support complex options (yet) * Grammar nit * Update extract text webpack plugin * - Remove webpack.LoaderOptionsPlugin - Update deps * Lerna hoists packages * Update extract-text-webpack-plugin * Update webpack-dev-server * Remove imports for the tests * stop removing babelrc
1 parent d93e90a commit cca16df

File tree

8 files changed

+122
-97
lines changed

8 files changed

+122
-97
lines changed

packages/babel-preset-react-app/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ if (env === 'test') {
8888
module.exports = {
8989
presets: [
9090
// Latest stable ECMAScript features
91-
require.resolve('babel-preset-latest'),
91+
[require.resolve('babel-preset-latest'), {
92+
'es2015': {
93+
modules: false
94+
}
95+
}],
9296
// JSX, Flow
9397
require.resolve('babel-preset-react')
9498
],

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ module.exports = {
8181
resolve: {
8282
// This allows you to set a fallback for where Webpack should look for modules.
8383
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
84-
// We use `fallback` instead of `root` because we want `node_modules` to "win"
85-
// if there any conflicts. This matches Node resolution mechanism.
84+
// We placed these paths second because we want `node_modules` to "win"
85+
// if there are any conflicts. This matches Node resolution mechanism.
8686
// https://github.com/facebookincubator/create-react-app/issues/253
87-
fallback: paths.nodePaths,
87+
modules: ['node_modules'].concat(paths.nodePaths),
8888
// These are the reasonable defaults supported by the Node ecosystem.
8989
// We also include JSX as a common component filename extension to support
9090
// some tools, although we do not recommend using it, see:
9191
// https://github.com/facebookincubator/create-react-app/issues/290
92-
extensions: ['.js', '.json', '.jsx', ''],
92+
extensions: ['.js', '.json', '.jsx'],
9393
alias: {
9494
// Support React Native Web
9595
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -100,21 +100,32 @@ module.exports = {
100100
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
101101
// directory of `react-scripts` itself rather than the project directory.
102102
resolveLoader: {
103-
root: paths.ownNodeModules,
104-
moduleTemplates: ['*-loader']
103+
modules: [
104+
paths.ownNodeModules,
105+
// Lerna hoists everything, so we need to look in our app directory
106+
paths.appNodeModules
107+
]
105108
},
106109
// @remove-on-eject-end
107110
module: {
108-
// First, run the linter.
109-
// It's important to do this before Babel processes the JS.
110-
preLoaders: [
111+
rules: [
112+
// First, run the linter.
113+
// It's important to do this before Babel processes the JS.
111114
{
112115
test: /\.(js|jsx)$/,
113-
loader: 'eslint',
114-
include: paths.appSrc,
115-
}
116-
],
117-
loaders: [
116+
enforce: 'pre',
117+
use: [{
118+
// @remove-on-eject-begin
119+
// Point ESLint to our predefined config.
120+
options: {
121+
configFile: path.join(__dirname, '../.eslintrc'),
122+
useEslintrc: false
123+
},
124+
// @remove-on-eject-end
125+
loader: 'eslint-loader'
126+
}],
127+
include: paths.appSrc
128+
},
118129
// ** ADDING/UPDATING LOADERS **
119130
// The "url" loader handles all assets unless explicitly excluded.
120131
// The `exclude` list *must* be updated with every change to loader extensions.
@@ -131,8 +142,8 @@ module.exports = {
131142
/\.json$/,
132143
/\.svg$/
133144
],
134-
loader: 'url',
135-
query: {
145+
loader: 'url-loader',
146+
options: {
136147
limit: 10000,
137148
name: 'static/media/[name].[hash:8].[ext]'
138149
}
@@ -141,8 +152,8 @@ module.exports = {
141152
{
142153
test: /\.(js|jsx)$/,
143154
include: paths.appSrc,
144-
loader: 'babel',
145-
query: {
155+
loader: 'babel-loader',
156+
options: {
146157
// @remove-on-eject-begin
147158
babelrc: false,
148159
presets: [require.resolve('babel-preset-react-app')],
@@ -160,35 +171,33 @@ module.exports = {
160171
// in development "style" loader enables hot editing of CSS.
161172
{
162173
test: /\.css$/,
163-
loader: 'style!css?importLoaders=1!postcss'
164-
},
165-
// JSON is not enabled by default in Webpack but both Node and Browserify
166-
// allow it implicitly so we also enable it.
167-
{
168-
test: /\.json$/,
169-
loader: 'json'
174+
use: [
175+
'style-loader', {
176+
loader: 'css-loader',
177+
options: {
178+
importLoaders: 1
179+
}
180+
}, {
181+
loader: 'postcss-loader',
182+
options: {
183+
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
184+
plugins: postcss
185+
}
186+
}
187+
]
170188
},
171189
// "file" loader for svg
172190
{
173191
test: /\.svg$/,
174-
loader: 'file',
175-
query: {
192+
loader: 'file-loader',
193+
options: {
176194
name: 'static/media/[name].[hash:8].[ext]'
177195
}
178196
}
179197
// ** STOP ** Are you adding a new loader?
180198
// Remember to add the new extension(s) to the "url" loader exclusion list.
181199
]
182200
},
183-
// @remove-on-eject-begin
184-
// Point ESLint to our predefined config.
185-
eslint: {
186-
configFile: './.eslintrc',
187-
useEslintrc: false
188-
},
189-
// @remove-on-eject-end
190-
// We use PostCSS for autoprefixing only.
191-
postcss: postcss,
192201
plugins: [
193202
// Makes some environment variables available in index.html.
194203
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
@@ -224,5 +233,11 @@ module.exports = {
224233
fs: 'empty',
225234
net: 'empty',
226235
tls: 'empty'
236+
},
237+
// Turn off performance hints during development because we don't do any
238+
// splitting or minification in interest of speed. These warnings become
239+
// cumbersome.
240+
performance: {
241+
hints: false
227242
}
228243
};

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const cssFilename = 'static/css/[name].[contenthash:8].css';
5555
// To have this structure working with relative paths, we have to use custom options.
5656
const extractTextPluginOptions = shouldUseRelativeAssetPaths
5757
// Making sure that the publicPath goes back to to build folder.
58-
? { publicPath: Array(cssFilename.split('/').length).join('../') }
59-
: undefined;
58+
? {publicPath: Array(cssFilename.split('/').length).join('../')}
59+
: {};
6060

6161
// This is the production configuration.
6262
// It compiles slowly and is focused on producing a fast and minimal bundle.
@@ -86,15 +86,15 @@ module.exports = {
8686
resolve: {
8787
// This allows you to set a fallback for where Webpack should look for modules.
8888
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
89-
// We use `fallback` instead of `root` because we want `node_modules` to "win"
90-
// if there any conflicts. This matches Node resolution mechanism.
89+
// We placed these paths second because we want `node_modules` to "win"
90+
// if there are any conflicts. This matches Node resolution mechanism.
9191
// https://github.com/facebookincubator/create-react-app/issues/253
92-
fallback: paths.nodePaths,
92+
modules: ['node_modules'].concat(paths.nodePaths),
9393
// These are the reasonable defaults supported by the Node ecosystem.
9494
// We also include JSX as a common component filename extension to support
9595
// some tools, although we do not recommend using it, see:
9696
// https://github.com/facebookincubator/create-react-app/issues/290
97-
extensions: ['.js', '.json', '.jsx', ''],
97+
extensions: ['.js', '.json', '.jsx'],
9898
alias: {
9999
// Support React Native Web
100100
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -105,21 +105,34 @@ module.exports = {
105105
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
106106
// directory of `react-scripts` itself rather than the project directory.
107107
resolveLoader: {
108-
root: paths.ownNodeModules,
109-
moduleTemplates: ['*-loader']
108+
modules: [
109+
paths.ownNodeModules,
110+
// Lerna hoists everything, so we need to look in our app directory
111+
paths.appNodeModules
112+
]
110113
},
111114
// @remove-on-eject-end
112115
module: {
113-
// First, run the linter.
114-
// It's important to do this before Babel processes the JS.
115-
preLoaders: [
116+
rules: [
117+
// First, run the linter.
118+
// It's important to do this before Babel processes the JS.
116119
{
117120
test: /\.(js|jsx)$/,
118-
loader: 'eslint',
121+
enforce: 'pre',
122+
use: [{
123+
// @remove-on-eject-begin
124+
// Point ESLint to our predefined config.
125+
options: {
126+
// TODO: consider separate config for production,
127+
// e.g. to enable no-console and no-debugger only in production.
128+
configFile: path.join(__dirname, '../.eslintrc'),
129+
useEslintrc: false
130+
},
131+
// @remove-on-eject-end
132+
loader: 'eslint-loader'
133+
}],
119134
include: paths.appSrc
120-
}
121-
],
122-
loaders: [
135+
},
123136
// ** ADDING/UPDATING LOADERS **
124137
// The "url" loader handles all assets unless explicitly excluded.
125138
// The `exclude` list *must* be updated with every change to loader extensions.
@@ -136,8 +149,8 @@ module.exports = {
136149
/\.json$/,
137150
/\.svg$/
138151
],
139-
loader: 'url',
140-
query: {
152+
loader: 'url-loader',
153+
options: {
141154
limit: 10000,
142155
name: 'static/media/[name].[hash:8].[ext]'
143156
}
@@ -146,9 +159,9 @@ module.exports = {
146159
{
147160
test: /\.(js|jsx)$/,
148161
include: paths.appSrc,
149-
loader: 'babel',
162+
loader: 'babel-loader',
150163
// @remove-on-eject-begin
151-
query: {
164+
options: {
152165
babelrc: false,
153166
presets: [require.resolve('babel-preset-react-app')],
154167
},
@@ -168,42 +181,37 @@ module.exports = {
168181
// in the main CSS file.
169182
{
170183
test: /\.css$/,
171-
loader: ExtractTextPlugin.extract(
172-
'style',
173-
'css?importLoaders=1!postcss',
174-
extractTextPluginOptions
175-
)
184+
loader: ExtractTextPlugin.extract(Object.assign({
185+
fallback: 'style-loader',
186+
use: [
187+
{
188+
loader: 'css-loader',
189+
options: {
190+
importLoaders: 1
191+
}
192+
}, {
193+
loader: 'postcss-loader',
194+
options: {
195+
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
196+
plugins: postcss
197+
}
198+
}
199+
]
200+
}, extractTextPluginOptions))
176201
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
177202
},
178-
// JSON is not enabled by default in Webpack but both Node and Browserify
179-
// allow it implicitly so we also enable it.
180-
{
181-
test: /\.json$/,
182-
loader: 'json'
183-
},
184203
// "file" loader for svg
185204
{
186205
test: /\.svg$/,
187-
loader: 'file',
188-
query: {
206+
loader: 'file-loader',
207+
options: {
189208
name: 'static/media/[name].[hash:8].[ext]'
190209
}
191210
}
192211
// ** STOP ** Are you adding a new loader?
193212
// Remember to add the new extension(s) to the "url" loader exclusion list.
194213
]
195214
},
196-
// @remove-on-eject-begin
197-
// Point ESLint to our predefined config.
198-
eslint: {
199-
// TODO: consider separate config for production,
200-
// e.g. to enable no-console and no-debugger only in production.
201-
configFile: path.join(__dirname, '../.eslintrc'),
202-
useEslintrc: false
203-
},
204-
// @remove-on-eject-end
205-
// We use PostCSS for autoprefixing only.
206-
postcss: postcss,
207215
plugins: [
208216
// Makes some environment variables available in index.html.
209217
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
@@ -233,10 +241,6 @@ module.exports = {
233241
// It is absolutely essential that NODE_ENV was set to production here.
234242
// Otherwise React will be compiled in the very slow development mode.
235243
new webpack.DefinePlugin(env.stringified),
236-
// This helps ensure the builds are consistent if source hasn't changed:
237-
new webpack.optimize.OccurrenceOrderPlugin(),
238-
// Try to dedupe duplicated modules, if any:
239-
new webpack.optimize.DedupePlugin(),
240244
// Minify the code.
241245
new webpack.optimize.UglifyJsPlugin({
242246
compress: {
@@ -249,10 +253,13 @@ module.exports = {
249253
output: {
250254
comments: false,
251255
screw_ie8: true
252-
}
256+
},
257+
sourceMap: true
253258
}),
254259
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
255-
new ExtractTextPlugin(cssFilename),
260+
new ExtractTextPlugin({
261+
filename: cssFilename
262+
}),
256263
// Generate a manifest file which contains a mapping of all asset filenames
257264
// to their corresponding output file so that tools can pick it up without
258265
// having to parse `index.html`.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": ["react-app"]
2+
"presets": ["react-app"],
3+
"plugins": ["babel-plugin-transform-es2015-modules-commonjs"]
34
}

packages/react-scripts/fixtures/kitchensink/.template.dependencies.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"dependencies": {
33
"babel-register": "6.22.0",
4+
"babel-plugin-transform-es2015-modules-commonjs": "6.22.0",
45
"babel-polyfill": "6.20.0",
56
"chai": "3.5.0",
67
"jsdom": "9.8.3",

packages/react-scripts/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,19 @@
3939
"dotenv": "2.0.0",
4040
"eslint": "3.8.1",
4141
"eslint-config-react-app": "^0.5.1",
42-
"eslint-loader": "1.6.0",
42+
"eslint-loader": "1.6.1",
4343
"eslint-plugin-flowtype": "2.21.0",
4444
"eslint-plugin-import": "2.0.1",
4545
"eslint-plugin-jsx-a11y": "2.2.3",
4646
"eslint-plugin-react": "6.4.1",
47-
"extract-text-webpack-plugin": "1.0.1",
47+
"extract-text-webpack-plugin": "2.0.0-rc.3",
4848
"file-loader": "0.10.0",
4949
"filesize": "3.3.0",
5050
"fs-extra": "0.30.0",
5151
"gzip-size": "3.0.0",
52-
"html-webpack-plugin": "2.24.0",
52+
"html-webpack-plugin": "2.28.0",
5353
"http-proxy-middleware": "0.17.3",
5454
"jest": "18.1.0",
55-
"json-loader": "0.5.4",
5655
"object-assign": "4.1.1",
5756
"postcss-loader": "1.2.2",
5857
"postcss-cssnext": "^2.9.0",
@@ -73,8 +72,8 @@
7372
"style-loader": "0.13.1",
7473
"tachyons": "^4.6.1",
7574
"url-loader": "0.5.7",
76-
"webpack": "1.14.0",
77-
"webpack-dev-server": "1.16.2",
75+
"webpack": "2.2.1",
76+
"webpack-dev-server": "2.3.0",
7877
"webpack-manifest-plugin": "1.1.0",
7978
"whatwg-fetch": "2.0.2"
8079
},

0 commit comments

Comments
 (0)