Skip to content

Commit cfee807

Browse files
author
Morten N.O. Henriksen
committed
Update webpack and dev server
1 parent 4d0be4a commit cfee807

File tree

4 files changed

+74
-138
lines changed

4 files changed

+74
-138
lines changed

packages/react-error-overlay/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@
6565
"react-dom": "^17.0.1",
6666
"rimraf": "^3.0.2",
6767
"settle-promise": "1.0.0",
68-
"source-map": "0.5.7",
69-
"terser-webpack-plugin": "4.2.3",
70-
"webpack": "^4.44.2"
68+
"source-map": "0.7.3",
69+
"webpack": "^5.24.3"
7170
},
7271
"jest": {
7372
"setupFiles": [

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

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const fs = require('fs');
1212
const path = require('path');
1313
const webpack = require('webpack');
1414
const resolve = require('resolve');
15-
const PnpWebpackPlugin = require('pnp-webpack-plugin');
1615
const HtmlWebpackPlugin = require('html-webpack-plugin');
1716
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1817
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
@@ -167,6 +166,7 @@ module.exports = function (webpackEnv) {
167166
};
168167

169168
return {
169+
target: ['browserslist'],
170170
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
171171
// Stop compilation early in production
172172
bail: isEnvProduction,
@@ -212,8 +212,6 @@ module.exports = function (webpackEnv) {
212212
filename: isEnvProduction
213213
? 'static/js/[name].[contenthash:8].js'
214214
: isEnvDevelopment && 'static/js/bundle.js',
215-
// TODO: remove this when upgrading to webpack 5
216-
futureEmitAssets: true,
217215
// There are also additional JS chunk files if you use code splitting.
218216
chunkFilename: isEnvProduction
219217
? 'static/js/[name].[contenthash:8].chunk.js'
@@ -230,13 +228,13 @@ module.exports = function (webpackEnv) {
230228
.replace(/\\/g, '/')
231229
: isEnvDevelopment &&
232230
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
233-
// Prevents conflicts when multiple webpack runtimes (from different apps)
234-
// are used on the same page.
235-
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
236231
// this defaults to 'window', but by setting it to 'this' then
237232
// module chunks which are built will work in web workers as well.
238233
globalObject: 'this',
239234
},
235+
infrastructureLogging: {
236+
level: 'none',
237+
},
240238
optimization: {
241239
minimize: isEnvProduction,
242240
minimizer: [
@@ -279,38 +277,10 @@ module.exports = function (webpackEnv) {
279277
ascii_only: true,
280278
},
281279
},
282-
sourceMap: shouldUseSourceMap,
283280
}),
284281
// This is only used in production mode
285-
new CssMinimizerPlugin({
286-
sourceMap: shouldUseSourceMap
287-
? {
288-
// `inline: false` forces the sourcemap to be output into a
289-
// separate file
290-
inline: false,
291-
// `annotation: true` appends the sourceMappingURL to the end of
292-
// the css file, helping the browser find the sourcemap
293-
annotation: true,
294-
}
295-
: false,
296-
minimizerOptions: {
297-
preset: ['default', { minifyFontValues: { removeQuotes: false } }],
298-
},
299-
}),
282+
new CssMinimizerPlugin(),
300283
],
301-
// Automatically split vendor and commons
302-
// https://twitter.com/wSokra/status/969633336732905474
303-
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
304-
splitChunks: {
305-
chunks: 'all',
306-
name: isEnvDevelopment,
307-
},
308-
// Keep the runtime chunk separated to enable long term caching
309-
// https://twitter.com/wSokra/status/969679223278505985
310-
// https://github.com/facebook/create-react-app/issues/5358
311-
runtimeChunk: {
312-
name: entrypoint => `runtime-${entrypoint.name}`,
313-
},
314284
},
315285
resolve: {
316286
// This allows you to set a fallback for where webpack should look for modules.
@@ -341,9 +311,6 @@ module.exports = function (webpackEnv) {
341311
...(modules.webpackAliases || {}),
342312
},
343313
plugins: [
344-
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
345-
// guards against forgotten dependencies and such.
346-
PnpWebpackPlugin,
347314
// Prevents users from importing files from outside of src/ (or node_modules/).
348315
// This often causes confusion because we only process files within src/ with babel.
349316
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
@@ -355,13 +322,6 @@ module.exports = function (webpackEnv) {
355322
]),
356323
],
357324
},
358-
resolveLoader: {
359-
plugins: [
360-
// Also related to Plug'n'Play, but this time it tells webpack to load its loaders
361-
// from the current package.
362-
PnpWebpackPlugin.moduleLoader(module),
363-
],
364-
},
365325
module: {
366326
strictExportPresence: true,
367327
rules: [
@@ -753,15 +713,15 @@ module.exports = function (webpackEnv) {
753713
// '../cra-template-typescript/template/src/App.tsx'
754714
// otherwise.
755715
include: [
756-
'../**/src/**/*.{ts,tsx}',
757-
'**/src/**/*.{ts,tsx}',
758-
].map(file => ({ file })),
716+
{ file: '../**/src/**/*.{ts,tsx}' },
717+
{ file: '**/src/**/*.{ts,tsx}' },
718+
],
759719
exclude: [
760-
'**/src/**/__tests__/**',
761-
'**/src/**/?(*.)(spec|test).*',
762-
'**/src/setupProxy.*',
763-
'**/src/setupTests.*',
764-
].map(file => ({ file })),
720+
{ file: '**/src/**/__tests__/**' },
721+
{ file: '**/src/**/?(*.){spec|test}.*' },
722+
{ file: '**/src/setupProxy.*' },
723+
{ file: '**/src/setupTests.*' },
724+
],
765725
},
766726
logger: {
767727
infrastructure: 'silent',
@@ -793,18 +753,6 @@ module.exports = function (webpackEnv) {
793753
},
794754
}),
795755
].filter(Boolean),
796-
// Some libraries import Node modules but don't use them in the browser.
797-
// Tell webpack to provide empty mocks for them so importing them works.
798-
node: {
799-
module: 'empty',
800-
dgram: 'empty',
801-
dns: 'mock',
802-
fs: 'empty',
803-
http2: 'empty',
804-
net: 'empty',
805-
tls: 'empty',
806-
child_process: 'empty',
807-
},
808756
// Turn off performance processing because we utilize
809757
// our own hints via the FileSizeReporter
810758
performance: false,

packages/react-scripts/config/webpackDevServer.config.js

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const sockPath = process.env.WDS_SOCKET_PATH; // default: '/sockjs-node'
2323
const sockPort = process.env.WDS_SOCKET_PORT;
2424

2525
module.exports = function (proxy, allowedHost) {
26+
const disableFirewall =
27+
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true';
2628
return {
2729
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
2830
// websites from potentially accessing local content through DNS rebinding:
@@ -40,64 +42,54 @@ module.exports = function (proxy, allowedHost) {
4042
// So we will disable the host check normally, but enable it if you have
4143
// specified the `proxy` setting. Finally, we let you override it if you
4244
// really know what you're doing with a special environment variable.
43-
disableHostCheck:
44-
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
45+
// Note: ["localhost", ".localhost"] will support subdomains - but we might
46+
// want to allow setting the allowedHosts manually for more complex setups
47+
firewall: disableFirewall ? false : [allowedHost],
4548
// Enable gzip compression of generated files.
4649
compress: true,
47-
// Silence WebpackDevServer's own logs since they're generally not useful.
48-
// It will still show compile warnings and errors with this setting.
49-
clientLogLevel: 'none',
50-
// By default WebpackDevServer serves physical files from current directory
51-
// in addition to all the virtual build products that it serves from memory.
52-
// This is confusing because those files won’t automatically be available in
53-
// production build folder unless we copy them. However, copying the whole
54-
// project directory is dangerous because we may expose sensitive files.
55-
// Instead, we establish a convention that only files in `public` directory
56-
// get served. Our build script will copy `public` into the `build` folder.
57-
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
58-
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
59-
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
60-
// Note that we only recommend to use `public` folder as an escape hatch
61-
// for files like `favicon.ico`, `manifest.json`, and libraries that are
62-
// for some reason broken when imported through webpack. If you just want to
63-
// use an image, put it in `src` and `import` it from JavaScript instead.
64-
contentBase: paths.appPublic,
65-
contentBasePublicPath: paths.publicUrlOrPath,
66-
// By default files from `contentBase` will not trigger a page reload.
67-
watchContentBase: true,
68-
// Enable hot reloading server. It will provide WDS_SOCKET_PATH endpoint
69-
// for the WebpackDevServer client so it can learn when the files were
70-
// updated. The WebpackDevServer client is included as an entry point
71-
// in the webpack development configuration. Note that only changes
72-
// to CSS are currently hot reloaded. JS changes will refresh the browser.
73-
hot: true,
74-
// Use 'ws' instead of 'sockjs-node' on server since we're using native
75-
// websockets in `webpackHotDevClient`.
76-
transportMode: 'ws',
50+
static: {
51+
// By default WebpackDevServer serves physical files from current directory
52+
// in addition to all the virtual build products that it serves from memory.
53+
// This is confusing because those files won’t automatically be available in
54+
// production build folder unless we copy them. However, copying the whole
55+
// project directory is dangerous because we may expose sensitive files.
56+
// Instead, we establish a convention that only files in `public` directory
57+
// get served. Our build script will copy `public` into the `build` folder.
58+
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
59+
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
60+
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
61+
// Note that we only recommend to use `public` folder as an escape hatch
62+
// for files like `favicon.ico`, `manifest.json`, and libraries that are
63+
// for some reason broken when imported through webpack. If you just want to
64+
// use an image, put it in `src` and `import` it from JavaScript instead.
65+
directory: paths.appPublic,
66+
publicPath: [paths.publicUrlOrPath],
67+
// By default files from `contentBase` will not trigger a page reload.
68+
watch: {
69+
// Reportedly, this avoids CPU overload on some systems.
70+
// https://github.com/facebook/create-react-app/issues/293
71+
// src/node_modules is not ignored to support absolute imports
72+
// https://github.com/facebook/create-react-app/issues/1065
73+
ignored: ignoredFiles(paths.appSrc),
74+
},
75+
},
7776
// Prevent a WS client from getting injected as we're already including
7877
// `webpackHotDevClient`.
7978
injectClient: false,
80-
// Enable custom sockjs pathname for websocket connection to hot reloading server.
81-
// Enable custom sockjs hostname, pathname and port for websocket connection
82-
// to hot reloading server.
83-
sockHost,
84-
sockPath,
85-
sockPort,
79+
client: {
80+
// Enable custom sockjs pathname for websocket connection to hot reloading server.
81+
// Enable custom sockjs hostname, pathname and port for websocket connection
82+
// to hot reloading server.
83+
host: sockHost,
84+
path: sockPath,
85+
port: sockPort,
86+
},
8687
// It is important to tell WebpackDevServer to use the same "publicPath" path as
8788
// we specified in the webpack config. When homepage is '.', default to serving
8889
// from the root.
8990
// remove last slash so user can land on `/test` instead of `/test/`
9091
publicPath: paths.publicUrlOrPath.slice(0, -1),
91-
// WebpackDevServer is noisy by default so we emit custom message instead
92-
// by listening to the compiler events with `compiler.hooks[...].tap` calls above.
93-
quiet: true,
94-
// Reportedly, this avoids CPU overload on some systems.
95-
// https://github.com/facebook/create-react-app/issues/293
96-
// src/node_modules is not ignored to support absolute imports
97-
// https://github.com/facebook/create-react-app/issues/1065
98-
watchOptions: {
99-
ignored: ignoredFiles(paths.appSrc),
100-
},
92+
10193
https: getHttpsConfig(),
10294
host,
10395
overlay: false,
@@ -107,10 +99,9 @@ module.exports = function (proxy, allowedHost) {
10799
disableDotRule: true,
108100
index: paths.publicUrlOrPath,
109101
},
110-
public: allowedHost,
111102
// `proxy` is run between `before` and `after` `webpack-dev-server` hooks
112103
proxy,
113-
before(app, server) {
104+
onBeforeSetupMiddleware(app, server) {
114105
// Keep `evalSourceMapMiddleware` and `errorOverlayMiddleware`
115106
// middlewares before `redirectServedPath` otherwise will not have any effect
116107
// This lets us fetch source contents from webpack for the error overlay
@@ -123,7 +114,7 @@ module.exports = function (proxy, allowedHost) {
123114
require(paths.proxySetup)(app);
124115
}
125116
},
126-
after(app) {
117+
onAfterSetupMiddleware(app) {
127118
// Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
128119
app.use(redirectServedPath(paths.publicUrlOrPath));
129120

packages/react-scripts/package.json

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
},
2929
"types": "./lib/react-app.d.ts",
3030
"dependencies": {
31-
"@babel/core": "7.12.3",
32-
"@pmmmwh/react-refresh-webpack-plugin": "0.4.3",
31+
"@babel/core": "7.13.8",
32+
"@pmmmwh/react-refresh-webpack-plugin": "0.5.0-beta.1",
3333
"@svgr/webpack": "5.5.0",
3434
"@typescript-eslint/eslint-plugin": "^4.5.0",
3535
"@typescript-eslint/parser": "^4.5.0",
@@ -40,9 +40,9 @@
4040
"babel-preset-react-app": "^10.0.0",
4141
"bfj": "^7.0.2",
4242
"camelcase": "^6.1.0",
43-
"case-sensitive-paths-webpack-plugin": "2.3.0",
44-
"css-loader": "4.3.0",
45-
"css-minimizer-webpack-plugin": "1.1.5",
43+
"case-sensitive-paths-webpack-plugin": "2.4.0",
44+
"css-loader": "5.1.1",
45+
"css-minimizer-webpack-plugin": "1.2.0",
4646
"dotenv": "8.2.0",
4747
"dotenv-expand": "5.1.0",
4848
"eslint": "^7.11.0",
@@ -55,35 +55,33 @@
5555
"eslint-plugin-react-hooks": "^4.2.0",
5656
"eslint-plugin-testing-library": "^3.9.2",
5757
"eslint-webpack-plugin": "^2.5.2",
58-
"file-loader": "6.1.1",
58+
"file-loader": "6.2.0",
5959
"fs-extra": "^9.0.1",
60-
"html-webpack-plugin": "4.5.0",
60+
"html-webpack-plugin": "5.2.0",
6161
"identity-obj-proxy": "3.0.0",
6262
"jest": "26.6.0",
6363
"jest-circus": "26.6.0",
6464
"jest-resolve": "26.6.0",
6565
"jest-watch-typeahead": "0.6.1",
66-
"mini-css-extract-plugin": "0.11.3",
67-
"pnp-webpack-plugin": "1.6.4",
68-
"postcss": "8.2.4",
66+
"mini-css-extract-plugin": "1.3.9",
67+
"postcss": "8.2.7",
6968
"postcss-flexbugs-fixes": "5.0.2",
70-
"postcss-loader": "4.2.0",
69+
"postcss-loader": "5.1.0",
7170
"postcss-normalize": "9.0.0",
7271
"postcss-preset-env": "6.7.0",
7372
"prompts": "2.4.0",
7473
"react-app-polyfill": "^2.0.0",
7574
"react-dev-utils": "^11.0.3",
76-
"react-refresh": "^0.8.3",
77-
"resolve": "1.18.1",
75+
"react-refresh": "^0.9.0",
76+
"resolve": "1.20.0",
7877
"resolve-url-loader": "^3.1.2",
79-
"sass-loader": "^10.0.5",
80-
"semver": "7.3.2",
81-
"style-loader": "1.3.0",
82-
"terser-webpack-plugin": "4.2.3",
78+
"sass-loader": "^11.0.1",
79+
"semver": "7.3.4",
80+
"style-loader": "2.0.0",
8381
"ts-pnp": "1.2.0",
8482
"url-loader": "4.1.1",
85-
"webpack": "4.44.2",
86-
"webpack-dev-server": "3.11.1",
83+
"webpack": "5.24.3",
84+
"webpack-dev-server": "4.0.0-beta.0",
8785
"webpack-manifest-plugin": "3.0.0",
8886
"workbox-webpack-plugin": "5.1.4"
8987
},

0 commit comments

Comments
 (0)