Skip to content

Commit 3bb37fa

Browse files
Timerbondz
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 05041f7 commit 3bb37fa

File tree

8 files changed

+144
-119
lines changed

8 files changed

+144
-119
lines changed

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

+5-1
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

+62-47
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ module.exports = {
7878
resolve: {
7979
// This allows you to set a fallback for where Webpack should look for modules.
8080
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
81-
// We use `fallback` instead of `root` because we want `node_modules` to "win"
82-
// if there any conflicts. This matches Node resolution mechanism.
81+
// We placed these paths second because we want `node_modules` to "win"
82+
// if there are any conflicts. This matches Node resolution mechanism.
8383
// https://github.com/facebookincubator/create-react-app/issues/253
84-
fallback: paths.nodePaths,
84+
modules: ['node_modules'].concat(paths.nodePaths),
8585
// These are the reasonable defaults supported by the Node ecosystem.
8686
// We also include JSX as a common component filename extension to support
8787
// some tools, although we do not recommend using it, see:
8888
// https://github.com/facebookincubator/create-react-app/issues/290
89-
extensions: ['.js', '.json', '.jsx', ''],
89+
extensions: ['.js', '.json', '.jsx'],
9090
alias: {
9191
// Support React Native Web
9292
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -97,21 +97,32 @@ module.exports = {
9797
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
9898
// directory of `react-scripts` itself rather than the project directory.
9999
resolveLoader: {
100-
root: paths.ownNodeModules,
101-
moduleTemplates: ['*-loader']
100+
modules: [
101+
paths.ownNodeModules,
102+
// Lerna hoists everything, so we need to look in our app directory
103+
paths.appNodeModules
104+
]
102105
},
103106
// @remove-on-eject-end
104107
module: {
105-
// First, run the linter.
106-
// It's important to do this before Babel processes the JS.
107-
preLoaders: [
108+
rules: [
109+
// First, run the linter.
110+
// It's important to do this before Babel processes the JS.
108111
{
109112
test: /\.(js|jsx)$/,
110-
loader: 'eslint',
111-
include: paths.appSrc,
112-
}
113-
],
114-
loaders: [
113+
enforce: 'pre',
114+
use: [{
115+
// @remove-on-eject-begin
116+
// Point ESLint to our predefined config.
117+
options: {
118+
configFile: path.join(__dirname, '../.eslintrc'),
119+
useEslintrc: false
120+
},
121+
// @remove-on-eject-end
122+
loader: 'eslint-loader'
123+
}],
124+
include: paths.appSrc
125+
},
115126
// ** ADDING/UPDATING LOADERS **
116127
// The "url" loader handles all assets unless explicitly excluded.
117128
// The `exclude` list *must* be updated with every change to loader extensions.
@@ -128,8 +139,8 @@ module.exports = {
128139
/\.json$/,
129140
/\.svg$/
130141
],
131-
loader: 'url',
132-
query: {
142+
loader: 'url-loader',
143+
options: {
133144
limit: 10000,
134145
name: 'static/media/[name].[hash:8].[ext]'
135146
}
@@ -138,8 +149,8 @@ module.exports = {
138149
{
139150
test: /\.(js|jsx)$/,
140151
include: paths.appSrc,
141-
loader: 'babel',
142-
query: {
152+
loader: 'babel-loader',
153+
options: {
143154
// @remove-on-eject-begin
144155
babelrc: false,
145156
presets: [require.resolve('babel-preset-react-app')],
@@ -157,46 +168,44 @@ module.exports = {
157168
// in development "style" loader enables hot editing of CSS.
158169
{
159170
test: /\.css$/,
160-
loader: 'style!css?importLoaders=1!postcss'
161-
},
162-
// JSON is not enabled by default in Webpack but both Node and Browserify
163-
// allow it implicitly so we also enable it.
164-
{
165-
test: /\.json$/,
166-
loader: 'json'
171+
use: [
172+
'style-loader', {
173+
loader: 'css-loader',
174+
options: {
175+
importLoaders: 1
176+
}
177+
}, {
178+
loader: 'postcss-loader',
179+
options: {
180+
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
181+
plugins: function () {
182+
return [
183+
autoprefixer({
184+
browsers: [
185+
'>1%',
186+
'last 4 versions',
187+
'Firefox ESR',
188+
'not ie < 9', // React doesn't support IE8 anyway
189+
]
190+
})
191+
]
192+
}
193+
}
194+
}
195+
]
167196
},
168197
// "file" loader for svg
169198
{
170199
test: /\.svg$/,
171-
loader: 'file',
172-
query: {
200+
loader: 'file-loader',
201+
options: {
173202
name: 'static/media/[name].[hash:8].[ext]'
174203
}
175204
}
176205
// ** STOP ** Are you adding a new loader?
177206
// Remember to add the new extension(s) to the "url" loader exclusion list.
178207
]
179208
},
180-
// @remove-on-eject-begin
181-
// Point ESLint to our predefined config.
182-
eslint: {
183-
configFile: path.join(__dirname, '../.eslintrc'),
184-
useEslintrc: false
185-
},
186-
// @remove-on-eject-end
187-
// We use PostCSS for autoprefixing only.
188-
postcss: function() {
189-
return [
190-
autoprefixer({
191-
browsers: [
192-
'>1%',
193-
'last 4 versions',
194-
'Firefox ESR',
195-
'not ie < 9', // React doesn't support IE8 anyway
196-
]
197-
}),
198-
];
199-
},
200209
plugins: [
201210
// Makes some environment variables available in index.html.
202211
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
@@ -229,5 +238,11 @@ module.exports = {
229238
fs: 'empty',
230239
net: 'empty',
231240
tls: 'empty'
241+
},
242+
// Turn off performance hints during development because we don't do any
243+
// splitting or minification in interest of speed. These warnings become
244+
// cumbersome.
245+
performance: {
246+
hints: false
232247
}
233248
};

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

+67-60
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ const cssFilename = 'static/css/[name].[contenthash:8].css';
5252
// To have this structure working with relative paths, we have to use custom options.
5353
const extractTextPluginOptions = shouldUseRelativeAssetPaths
5454
// Making sure that the publicPath goes back to to build folder.
55-
? { publicPath: Array(cssFilename.split('/').length).join('../') }
56-
: undefined;
55+
? {publicPath: Array(cssFilename.split('/').length).join('../')}
56+
: {};
5757

5858
// This is the production configuration.
5959
// It compiles slowly and is focused on producing a fast and minimal bundle.
@@ -83,15 +83,15 @@ module.exports = {
8383
resolve: {
8484
// This allows you to set a fallback for where Webpack should look for modules.
8585
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
86-
// We use `fallback` instead of `root` because we want `node_modules` to "win"
87-
// if there any conflicts. This matches Node resolution mechanism.
86+
// We placed these paths second because we want `node_modules` to "win"
87+
// if there are any conflicts. This matches Node resolution mechanism.
8888
// https://github.com/facebookincubator/create-react-app/issues/253
89-
fallback: paths.nodePaths,
89+
modules: ['node_modules'].concat(paths.nodePaths),
9090
// These are the reasonable defaults supported by the Node ecosystem.
9191
// We also include JSX as a common component filename extension to support
9292
// some tools, although we do not recommend using it, see:
9393
// https://github.com/facebookincubator/create-react-app/issues/290
94-
extensions: ['.js', '.json', '.jsx', ''],
94+
extensions: ['.js', '.json', '.jsx'],
9595
alias: {
9696
// Support React Native Web
9797
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -102,21 +102,34 @@ module.exports = {
102102
// Resolve loaders (webpack plugins for CSS, images, transpilation) from the
103103
// directory of `react-scripts` itself rather than the project directory.
104104
resolveLoader: {
105-
root: paths.ownNodeModules,
106-
moduleTemplates: ['*-loader']
105+
modules: [
106+
paths.ownNodeModules,
107+
// Lerna hoists everything, so we need to look in our app directory
108+
paths.appNodeModules
109+
]
107110
},
108111
// @remove-on-eject-end
109112
module: {
110-
// First, run the linter.
111-
// It's important to do this before Babel processes the JS.
112-
preLoaders: [
113+
rules: [
114+
// First, run the linter.
115+
// It's important to do this before Babel processes the JS.
113116
{
114117
test: /\.(js|jsx)$/,
115-
loader: 'eslint',
118+
enforce: 'pre',
119+
use: [{
120+
// @remove-on-eject-begin
121+
// Point ESLint to our predefined config.
122+
options: {
123+
// TODO: consider separate config for production,
124+
// e.g. to enable no-console and no-debugger only in production.
125+
configFile: path.join(__dirname, '../.eslintrc'),
126+
useEslintrc: false
127+
},
128+
// @remove-on-eject-end
129+
loader: 'eslint-loader'
130+
}],
116131
include: paths.appSrc
117-
}
118-
],
119-
loaders: [
132+
},
120133
// ** ADDING/UPDATING LOADERS **
121134
// The "url" loader handles all assets unless explicitly excluded.
122135
// The `exclude` list *must* be updated with every change to loader extensions.
@@ -133,8 +146,8 @@ module.exports = {
133146
/\.json$/,
134147
/\.svg$/
135148
],
136-
loader: 'url',
137-
query: {
149+
loader: 'url-loader',
150+
options: {
138151
limit: 10000,
139152
name: 'static/media/[name].[hash:8].[ext]'
140153
}
@@ -143,9 +156,9 @@ module.exports = {
143156
{
144157
test: /\.(js|jsx)$/,
145158
include: paths.appSrc,
146-
loader: 'babel',
159+
loader: 'babel-loader',
147160
// @remove-on-eject-begin
148-
query: {
161+
options: {
149162
babelrc: false,
150163
presets: [require.resolve('babel-preset-react-app')],
151164
},
@@ -165,53 +178,48 @@ module.exports = {
165178
// in the main CSS file.
166179
{
167180
test: /\.css$/,
168-
loader: ExtractTextPlugin.extract(
169-
'style',
170-
'css?importLoaders=1!postcss',
171-
extractTextPluginOptions
172-
)
181+
loader: ExtractTextPlugin.extract(Object.assign({
182+
fallback: 'style-loader',
183+
use: [
184+
{
185+
loader: 'css-loader',
186+
options: {
187+
importLoaders: 1
188+
}
189+
}, {
190+
loader: 'postcss-loader',
191+
options: {
192+
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
193+
plugins: function () {
194+
return [
195+
autoprefixer({
196+
browsers: [
197+
'>1%',
198+
'last 4 versions',
199+
'Firefox ESR',
200+
'not ie < 9', // React doesn't support IE8 anyway
201+
]
202+
})
203+
]
204+
}
205+
}
206+
}
207+
]
208+
}, extractTextPluginOptions))
173209
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
174210
},
175-
// JSON is not enabled by default in Webpack but both Node and Browserify
176-
// allow it implicitly so we also enable it.
177-
{
178-
test: /\.json$/,
179-
loader: 'json'
180-
},
181211
// "file" loader for svg
182212
{
183213
test: /\.svg$/,
184-
loader: 'file',
185-
query: {
214+
loader: 'file-loader',
215+
options: {
186216
name: 'static/media/[name].[hash:8].[ext]'
187217
}
188218
}
189219
// ** STOP ** Are you adding a new loader?
190220
// Remember to add the new extension(s) to the "url" loader exclusion list.
191221
]
192222
},
193-
// @remove-on-eject-begin
194-
// Point ESLint to our predefined config.
195-
eslint: {
196-
// TODO: consider separate config for production,
197-
// e.g. to enable no-console and no-debugger only in production.
198-
configFile: path.join(__dirname, '../.eslintrc'),
199-
useEslintrc: false
200-
},
201-
// @remove-on-eject-end
202-
// We use PostCSS for autoprefixing only.
203-
postcss: function() {
204-
return [
205-
autoprefixer({
206-
browsers: [
207-
'>1%',
208-
'last 4 versions',
209-
'Firefox ESR',
210-
'not ie < 9', // React doesn't support IE8 anyway
211-
]
212-
}),
213-
];
214-
},
215223
plugins: [
216224
// Makes some environment variables available in index.html.
217225
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
@@ -241,10 +249,6 @@ module.exports = {
241249
// It is absolutely essential that NODE_ENV was set to production here.
242250
// Otherwise React will be compiled in the very slow development mode.
243251
new webpack.DefinePlugin(env.stringified),
244-
// This helps ensure the builds are consistent if source hasn't changed:
245-
new webpack.optimize.OccurrenceOrderPlugin(),
246-
// Try to dedupe duplicated modules, if any:
247-
new webpack.optimize.DedupePlugin(),
248252
// Minify the code.
249253
new webpack.optimize.UglifyJsPlugin({
250254
compress: {
@@ -257,10 +261,13 @@ module.exports = {
257261
output: {
258262
comments: false,
259263
screw_ie8: true
260-
}
264+
},
265+
sourceMap: true
261266
}),
262267
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
263-
new ExtractTextPlugin(cssFilename),
268+
new ExtractTextPlugin({
269+
filename: cssFilename
270+
}),
264271
// Generate a manifest file which contains a mapping of all asset filenames
265272
// to their corresponding output file so that tools can pick it up without
266273
// having to parse `index.html`.
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
}

0 commit comments

Comments
 (0)