Я использую Webpack для подготовки производственной сборки моего ReactJS сайта.
Я следил за документами Webpack, но моя производственная сборка (после минификации) колоссальная 1.88MiB .
WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). Th
is can impact web performance.
Entrypoints:
main (1.88 MiB)
bundle.js
Использование BundleAnalyzerPlugin
Я получаю это:
bundle.js: 1.88MB (parsed size)
src: 1.04MB (parsed size)
node_modules: 852.17KB (parsed size)
Я не совсем понимаю, почему я вижу node_modules/@fortawesome
внутри src/js
...
Вот мой конфиг:
webpack.common. js
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
module.exports = {
entry: path.resolve(__dirname, 'src/js/index.jsx'),
plugins: [
new CopyWebpackPlugin([
{
context: path.resolve(__dirname, 'src/'),
from: 'index.html',
to: path.resolve(__dirname, 'dist'),
},
]),
new BundleAnalyzerPlugin(),
],
output: {
filename: 'bundle.js',
publicPath: '/',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
Components: path.resolve(__dirname, 'src/js/components'),
Images: path.resolve(__dirname, 'src/images'),
},
},
module: {
rules: [
{
test: /\.js$|.jsx$/,
exclude: /(node_modules|bower_components)/,
use: ['babel-loader', 'eslint-loader'],
},
{
test: /(\.css|\.scss)$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.(png|jp(e*)g|JPG|svg|mov|mp4|webm|ogv)$/,
use: ['file-loader?name=[name].[ext]&outputPath=images/&publicPath=/images/', 'image-webpack-loader'],
},
],
},
};
webpack.prod. js
const TerserPlugin = require('terser-webpack-plugin');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: 'production',
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
parallel: true,
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
})],
},
});
Что можно сделать, чтобы уменьшить размер?