Размер файла webpack main.js составляет 6,3 в режиме "webpack --mode production".
Я использую webpack для объединения django & React js. но файл main.js bundle слишком большой (6.3 MB) поэтому страница долго загружается
webpack.config.js
const path = require("path");
const webpack = require("webpack");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "./static/frontend"),
filename: "[name].js",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
// Additional configuration to handle *.css files
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.svg$/,
use: ["@svgr/webpack"],
use: [
{
loader: "svg-url-loader",
options: {
limit: 10000,
},
},
],
},
{
test: /\.(png|jpg)$/,
type: "asset/resource",
},
],
},
optimization: {
minimize: true,
},
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
plugins: [
new NodePolyfillPlugin(),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production"),
}),
],
};
babel.config.json
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10"
}
}
],
"@babel/preset-react"
],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
Мой pakage.json Installed is
- "webpack": "^5.75.0",
- "webpack-cli": "^5.0.0"
Я не могу оптимизировать с помощью minimize = true. Он показывает ошибку, когда minimize = true
ERROR в main.js main.js от плагина Terser