Skip to content

Commit

Permalink
Upgrade webpack from v4 to v5 (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepnschrodinger authored Oct 24, 2024
1 parent 4828b1b commit 55c53f6
Show file tree
Hide file tree
Showing 4 changed files with 361 additions and 1,755 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@
"babel-loader": "^8.2.2",
"babel-plugin-rewire": "1.2.0",
"babel-plugin-syntax-trailing-function-commas": "^6.8.0",
"bundle-loader": "0.5.6",
"css-loader": "^5.2.7",
"eslint": "7",
"eslint-config-prettier": "6.10.0",
"except": "^0.1.3",
"faker": "^5.5.3",
"file-loader": "4.2.0",
"glob": "7.1.4",
"global": "^4.4.0",
"html-loader": "0.5.5",
Expand Down Expand Up @@ -77,8 +75,7 @@
"rollup-plugin-terser": "^7.0.2",
"style-loader": "1.0.0",
"terser-webpack-plugin": "4.2.3",
"url-loader": "2.1.0",
"webpack": "^4.39.3",
"webpack": "^5.94.0",
"webpack-cli": "^4.3.0",
"webpack-dev-server": "^4.7.4"
},
Expand Down
29 changes: 20 additions & 9 deletions site/webpack-client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');

const isDev = process.env.NODE_ENV !== 'production';
const nodeEnv = process.env.NODE_ENV ?? 'development';
const isDev = nodeEnv !== 'production';

module.exports = {
mode: isDev ? 'development' : 'production',
Expand All @@ -14,7 +15,7 @@ module.exports = {

output: {
path: path.resolve(__dirname, '../__site__/'),
filename: isDev ? '[name].js' : '[name]-[hash].js',
filename: isDev ? '[name].js' : '[name]-[contentHash].js',
publicPath: '',
},

Expand All @@ -24,10 +25,15 @@ module.exports = {
rules: [
{
test: /\.md$/,
loader: [
'html-loader?{"minimize":false}',
use: [
{
loader: 'html-loader',
options: {
minimize: false,
},
},
path.join(__dirname, '../build_helpers/markdownLoader'),
].join('!'),
],
},
{
test: /\.js$/,
Expand Down Expand Up @@ -63,8 +69,10 @@ module.exports = {
},
{
test: /\.png$/,
loader: 'file-loader',
query: { mimetype: 'image/png', name: 'images/[name]-[hash].[ext]' },
type: 'asset/resource',
generator: {
filename: 'images/[name]-[contentHash].[ext]',
},
},
],
},
Expand All @@ -74,6 +82,9 @@ module.exports = {
'fixed-data-table-2/css': path.join(__dirname, '../src/css'),
'fixed-data-table-2': path.join(__dirname, '../src/index'),
},
fallback: {
url: false,
},
},

devServer: {
Expand All @@ -83,10 +94,10 @@ module.exports = {

plugins: [
new MiniCssExtractPlugin({
filename: isDev ? '[name].css' : '[name]-[hash].css',
filename: isDev ? '[name].css' : '[name]-[contentHash].css',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.NODE_ENV': JSON.stringify(nodeEnv),
// 'process.env.NODE_ENV': JSON.stringify('production'),
__DEV__: isDev,
}),
Expand Down
27 changes: 20 additions & 7 deletions site/webpack-prerender.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');

const nodeEnv = process.env.NODE_ENV ?? 'development';
const isDev = process.env.NODE_ENV !== 'production';

module.exports = {
Expand All @@ -12,7 +13,9 @@ module.exports = {
output: {
path: path.resolve(__dirname, '../__site_prerender__/'),
filename: 'renderPath.js',
libraryTarget: 'commonjs2',
library: {
type: 'commonjs2',
},
},

target: 'node',
Expand All @@ -21,10 +24,15 @@ module.exports = {
rules: [
{
test: /\.md$/,
loader: [
'html-loader?{"minimize":false}',
use: [
{
loader: 'html-loader',
options: {
minimize: false,
},
},
path.join(__dirname, '../build_helpers/markdownLoader'),
].join('!'),
],
},
{
test: /\.js$/,
Expand All @@ -41,8 +49,10 @@ module.exports = {
},
{
test: /\.png$/,
loader: 'file-loader',
query: { mimetype: 'image/png', name: 'images/[name]-[hash].[ext]' },
type: 'asset/resource',
generator: {
filename: 'images/[name]-[contentHash].[ext]',
},
},
],
},
Expand All @@ -52,11 +62,14 @@ module.exports = {
'fixed-data-table-2/css': path.join(__dirname, '../src/css'),
'fixed-data-table-2': path.join(__dirname, '../src/index'),
},
fallback: {
url: false,
},
},

plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.NODE_ENV': JSON.stringify(nodeEnv),
__DEV__: isDev,
}),
],
Expand Down
Loading

0 comments on commit 55c53f6

Please sign in to comment.