// eslint-disable-next-line no-undef const path = require('path'); // eslint-disable-next-line no-undef const HtmlWebpackPlugin = require('html-webpack-plugin'); // eslint-disable-next-line no-undef const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // eslint-disable-next-line no-undef const {CleanWebpackPlugin} = require('clean-webpack-plugin'); // eslint-disable-next-line no-undef module.exports = (env, argv) => ({ entry: './src/app.js', output: { filename: '[hash].js', // eslint-disable-next-line no-undef path: path.resolve(__dirname, 'dist'), }, devServer: { compress: true, port: 9000, historyApiFallback: true, }, optimization: { splitChunks: { chunks: 'all', cacheGroups: { defaultVendors: { test: /[\\/]node_modules[\\/]/, enforce: true, }, } }, }, plugins: [ new CleanWebpackPlugin(), new HtmlWebpackPlugin({ filename: 'index.html', template: './src/app.html' }), new MiniCssExtractPlugin({ filename: '[hash].css', }), ], module: { rules: [ { test: /\.html$/i, loader: 'html-loader', }, { test: /\.css$/i, use: [ MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader' ], }, { test: /\.js$/, exclude: /node_modules/, use: [ 'babel-loader', { loader: 'eslint-loader', options: (argv.mode === 'production') ? { failOnError: true, failOnWarning: true, } : {}, } ] }, { test: /\.(gif|png|jpe?g|svg)$/i, loader: 'file-loader', }, { test: /\.(woff|woff2|eot|ttf|otf)$/, loader: 'file-loader', }, ], }, });