const ESLintPlugin = require('eslint-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin') const CssMinimizerPlugin = require('css-minimizer-webpack-plugin') const TerserPlugin = require('terser-webpack-plugin') module.exports = (env, argv) => { const dev = argv.mode !== 'production' const config = { devtool: dev ? 'source-map' : false, entry: { 'scripts': [ __dirname + '/src/main/assets/scripts.js', __dirname + '/src/main/assets/style.css' ] }, output: { path: __dirname + '/src/main/resources/static', filename: '[name].js' }, module: { rules: [{ test: /\.js$/, exclude: [ /\bnode_modules\b/, /\bcore-js\b/, /\bwebpack\/buildin\b/ ], loader: 'babel-loader' }, { test: /\.(css)$/, use: [ { loader: MiniCssExtractPlugin.loader, }, { loader: 'css-loader', options: { sourceMap: true, }, }, { loader: 'postcss-loader', options: { postcssOptions: { plugins: [ [ 'postcss-preset-env', 'stylelint', 'autoprefixer', { 'grid': true } ], ], }, }, }, ], }, { test: /\.(png|jpe?g|gif|svg)$/i, type: 'asset/resource' }] }, plugins: [ new MiniCssExtractPlugin({ filename: 'style.css' }) ], resolve: { symlinks: false, extensions: ['.js'] } } if (dev) { config.devServer = { hot: true, historyApiFallback: true, client: { overlay: { runtimeErrors: true } } } config.plugins.push( new ESLintPlugin({ files: 'src/main/assets', lintDirtyModulesOnly: true, failOnWarning: false, failOnError: true, fix: false })) } config.optimization = { minimize: !dev, minimizer: [ new TerserPlugin({ minify: TerserPlugin.swcMinify, // `terserOptions` options will be passed to `swc` (`@swc/core`) // Link to options - https://swc.rs/docs/config-js-minify terserOptions: {}, }), new CssMinimizerPlugin() ] } return config }