Skip to content

Commit 55c53f6

Browse files
Upgrade webpack from v4 to v5 (#734)
1 parent 4828b1b commit 55c53f6

File tree

4 files changed

+361
-1755
lines changed

4 files changed

+361
-1755
lines changed

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@
4343
"babel-loader": "^8.2.2",
4444
"babel-plugin-rewire": "1.2.0",
4545
"babel-plugin-syntax-trailing-function-commas": "^6.8.0",
46-
"bundle-loader": "0.5.6",
4746
"css-loader": "^5.2.7",
4847
"eslint": "7",
4948
"eslint-config-prettier": "6.10.0",
5049
"except": "^0.1.3",
5150
"faker": "^5.5.3",
52-
"file-loader": "4.2.0",
5351
"glob": "7.1.4",
5452
"global": "^4.4.0",
5553
"html-loader": "0.5.5",
@@ -77,8 +75,7 @@
7775
"rollup-plugin-terser": "^7.0.2",
7876
"style-loader": "1.0.0",
7977
"terser-webpack-plugin": "4.2.3",
80-
"url-loader": "2.1.0",
81-
"webpack": "^4.39.3",
78+
"webpack": "^5.94.0",
8279
"webpack-cli": "^4.3.0",
8380
"webpack-dev-server": "^4.7.4"
8481
},

site/webpack-client.config.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const webpack = require('webpack');
33
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
44
const TerserPlugin = require('terser-webpack-plugin');
55

6-
const isDev = process.env.NODE_ENV !== 'production';
6+
const nodeEnv = process.env.NODE_ENV ?? 'development';
7+
const isDev = nodeEnv !== 'production';
78

89
module.exports = {
910
mode: isDev ? 'development' : 'production',
@@ -14,7 +15,7 @@ module.exports = {
1415

1516
output: {
1617
path: path.resolve(__dirname, '../__site__/'),
17-
filename: isDev ? '[name].js' : '[name]-[hash].js',
18+
filename: isDev ? '[name].js' : '[name]-[contentHash].js',
1819
publicPath: '',
1920
},
2021

@@ -24,10 +25,15 @@ module.exports = {
2425
rules: [
2526
{
2627
test: /\.md$/,
27-
loader: [
28-
'html-loader?{"minimize":false}',
28+
use: [
29+
{
30+
loader: 'html-loader',
31+
options: {
32+
minimize: false,
33+
},
34+
},
2935
path.join(__dirname, '../build_helpers/markdownLoader'),
30-
].join('!'),
36+
],
3137
},
3238
{
3339
test: /\.js$/,
@@ -63,8 +69,10 @@ module.exports = {
6369
},
6470
{
6571
test: /\.png$/,
66-
loader: 'file-loader',
67-
query: { mimetype: 'image/png', name: 'images/[name]-[hash].[ext]' },
72+
type: 'asset/resource',
73+
generator: {
74+
filename: 'images/[name]-[contentHash].[ext]',
75+
},
6876
},
6977
],
7078
},
@@ -74,6 +82,9 @@ module.exports = {
7482
'fixed-data-table-2/css': path.join(__dirname, '../src/css'),
7583
'fixed-data-table-2': path.join(__dirname, '../src/index'),
7684
},
85+
fallback: {
86+
url: false,
87+
},
7788
},
7889

7990
devServer: {
@@ -83,10 +94,10 @@ module.exports = {
8394

8495
plugins: [
8596
new MiniCssExtractPlugin({
86-
filename: isDev ? '[name].css' : '[name]-[hash].css',
97+
filename: isDev ? '[name].css' : '[name]-[contentHash].css',
8798
}),
8899
new webpack.DefinePlugin({
89-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
100+
'process.env.NODE_ENV': JSON.stringify(nodeEnv),
90101
// 'process.env.NODE_ENV': JSON.stringify('production'),
91102
__DEV__: isDev,
92103
}),

site/webpack-prerender.config.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require('path');
22
const webpack = require('webpack');
33
const TerserPlugin = require('terser-webpack-plugin');
44

5+
const nodeEnv = process.env.NODE_ENV ?? 'development';
56
const isDev = process.env.NODE_ENV !== 'production';
67

78
module.exports = {
@@ -12,7 +13,9 @@ module.exports = {
1213
output: {
1314
path: path.resolve(__dirname, '../__site_prerender__/'),
1415
filename: 'renderPath.js',
15-
libraryTarget: 'commonjs2',
16+
library: {
17+
type: 'commonjs2',
18+
},
1619
},
1720

1821
target: 'node',
@@ -21,10 +24,15 @@ module.exports = {
2124
rules: [
2225
{
2326
test: /\.md$/,
24-
loader: [
25-
'html-loader?{"minimize":false}',
27+
use: [
28+
{
29+
loader: 'html-loader',
30+
options: {
31+
minimize: false,
32+
},
33+
},
2634
path.join(__dirname, '../build_helpers/markdownLoader'),
27-
].join('!'),
35+
],
2836
},
2937
{
3038
test: /\.js$/,
@@ -41,8 +49,10 @@ module.exports = {
4149
},
4250
{
4351
test: /\.png$/,
44-
loader: 'file-loader',
45-
query: { mimetype: 'image/png', name: 'images/[name]-[hash].[ext]' },
52+
type: 'asset/resource',
53+
generator: {
54+
filename: 'images/[name]-[contentHash].[ext]',
55+
},
4656
},
4757
],
4858
},
@@ -52,11 +62,14 @@ module.exports = {
5262
'fixed-data-table-2/css': path.join(__dirname, '../src/css'),
5363
'fixed-data-table-2': path.join(__dirname, '../src/index'),
5464
},
65+
fallback: {
66+
url: false,
67+
},
5568
},
5669

5770
plugins: [
5871
new webpack.DefinePlugin({
59-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
72+
'process.env.NODE_ENV': JSON.stringify(nodeEnv),
6073
__DEV__: isDev,
6174
}),
6275
],

0 commit comments

Comments
 (0)