// Imports const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin') const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const BabelRegister = require("babel-register"); const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); const devMode = process.env.NODE_ENV !== 'production' // Webpack Configuration const config = { // Entry entry: './src/app.js', // Output output: { path: path.resolve(__dirname, './dist'), filename: '[name].[chunkhash].js' }, optimization: { minimizer: [ new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: true, // set to true if you want JS source maps uglifyOptions: { output: { comments: false } } }), new OptimizeCSSAssetsPlugin({}) ], splitChunks: { cacheGroups: { commons: { chunks: "initial", minChunks: 2, maxInitialRequests: 5, minSize: 0 }, vendor: { test: /node_modules/, chunks: "initial", name: "vendor", priority: 10, enforce: true } } } }, module: { rules : [ { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } }, // CSS Files { test: /\.(sa|sc|c)ss$/, use: [ devMode ? 'style-loader' : MiniCssExtractPlugin.loader, 'css-loader', //'postcss-loader', 'sass-loader', ] }, { test: /\.(png|jpg|gif|svg)$/i, use: [ { loader: 'url-loader', options: { limit: 8192 } } ] } ] }, // Plugins plugins: [ new HtmlWebpackPlugin({ template: './src/template.html', filename: 'index.html', hash: true }), new MiniCssExtractPlugin({ filename: devMode ? '[name].css' : '[name].[hash].css', chunkFilename: devMode ? '[id].css' : '[id].[hash].css', }) ], // OPTIONAL // Reload On File Change watch: true, // Development Tools (Map Errors To Source File) devtool: 'source-map', }; // Exports module.exports = config;