const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); module.exports = (env, argv) => { const dev = argv.mode !== 'production'; const config = { devtool: dev ? 'source-map' : false, entry: { 'scripts': [ 'core-js/modules/es.array.index-of', 'core-js/modules/es.array.iterator', 'core-js/modules/es.array.map', 'core-js/modules/es.function.name', 'core-js/modules/es.object.create', 'core-js/modules/es.object.define-property', 'core-js/modules/es.object.keys', 'core-js/modules/es.object.set-prototype-of', 'core-js/modules/es.promise', 'core-js/modules/es.string.split', 'core-js/modules/es.symbol', 'core-js/modules/es.weak-map', 'core-js/modules/web.dom-collections.iterator', 'url-polyfill', 'whatwg-fetch', __dirname + '/src/main/assets/scripts.js', __dirname + '/src/main/assets/style.css', require.resolve('evil-icons/assets/sprite.svg'), require.resolve('evil-icons/assets/evil-icons.css') ] }, output: { path: __dirname + '/src/main/resources/static', filename: '[name].js' }, module: { rules: [ { test: /\.jsx?$/, loader: 'eslint-loader', enforce: 'pre', exclude: /node_modules/, options: { failOnWarning: false, failOnError: true, fix: true } }, { test: /\.js$/, loader: 'babel-loader' }, { test: /\.css$/, use: [ dev? 'style-loader' : MiniCssExtractPlugin.loader, { loader: 'css-loader' }, { loader: 'postcss-loader', options: { plugins: () => [ require('stylelint')(), require('postcss-preset-env')({ stage: 0, autoprefixer: { grid: true } }) ] } } ] }, { test: /\.(jpe?g|png|svg|gif)$/i, loaders: [ 'url-loader' ] } ] }, plugins: [ new MiniCssExtractPlugin({ filename: 'style.css', allChunks: true }) ], }; if (!dev) { config.optimization = { minimizer: [ new TerserPlugin({ cache: true, parallel: true, sourceMap: dev, terserOptions: { output: { comments: /@license/i } }, extractComments: true }), new OptimizeCSSAssetsPlugin({}) ] }; } return config; };