moner.ooo/webpack.config.js
Kumi 83a23fc66e
feat(build): optimize output with minification and compression
Switched to 'production' mode in webpack to enable optimizations. Integrated 'css-minimizer-webpack-plugin' and 'terser-webpack-plugin' for CSS and JS minification, respectively. Updated 'mini-css-extract-plugin' and added various dev dependencies to support new build processes. Adjusted output filenames and resolved dependencies to latest versions.

These changes reduce the bundle size and improve load times, enhancing overall performance.
2024-09-04 08:07:58 +02:00

54 lines
1.3 KiB
JavaScript

'use strict';
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { PurgeCSSPlugin } = require('purgecss-webpack-plugin');
const glob = require('glob-all');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
mode: 'production',
entry: './src/js/main.js',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'js'),
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '../css/[name].css'
}),
new PurgeCSSPlugin({
paths: glob.sync([
path.join(__dirname, 'index.php'),
path.join(__dirname, 'src/js/**/*.js')
]),
only: ['bootstrap'],
safelist: ['tooltip', 'fade', 'show', 'bs-tooltip-top', 'tooltip-inner', 'tooltip-arrow', 'btn-equals', 'btn-arrow', 'alert', 'alert-warning']
})
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
},
},
}),
new CssMinimizerPlugin(),
],
}
};