const ESLintPlugin = require('eslint-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const TerserPlugin = require('terser-webpack-plugin'); module.exports = (env, argv) => { const node_env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; const dev = node_env !== 'production'; const config = { mode: node_env, devtool: dev ? 'source-map' : false, entry: { 'index': [ __dirname + '/src/index.js' ] }, output: { path: __dirname + '/../public', filename: '[name].js' }, module: { rules: [{ test: /\.js$/, exclude: [ /\bnode_modules\b/, /\bcore-js\b/, /\bwebpack\/buildin\b/ ], loader: 'babel-loader' }, { test: /\.(css)$/, use: [ { loader: dev ? 'style-loader' : MiniCssExtractPlugin.loader, }, { loader: 'css-loader', options: { sourceMap: true, }, } ], }, { test: /\.(png|jpe?g|gif|svg)$/i, use: [ { loader: 'file-loader', }, ], }] }, plugins: [ new HtmlWebpackPlugin({ template: __dirname + '/src/index.html' }), ], resolve: { symlinks: false, extensions: ['.js'] } }; if (dev) { config.plugins.push( new ESLintPlugin({ files: __dirname + '/src', 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: {}, }), ] }; return config; };