aboutsummaryrefslogtreecommitdiff
path: root/webpack.config.js
blob: a2da5786d1c4db3ab0c0d2fcf69c300057b96f4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const ESLintPlugin = require('eslint-webpack-plugin');
const CopyPlugin = require('copy-webpack-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: {
            'scripts': [
                __dirname + '/src/main/assets/scripts.js'
            ]
        },
        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'
            }]
        },
        plugins: [
            new CopyPlugin({
                patterns: [{
                    from: __dirname + '/node_modules/evil-icons/assets/sprite.svg',
                    to: __dirname + '/src/main/resources/static/'
                }],
            }),
        ],
        resolve: {
            symlinks: false,
            extensions: ['.js']
        }
    };
    if (dev) {
        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.esbuildMinify,
                // `terserOptions` options will be passed to `esbuild`
                // Link to options - https://esbuild.github.io/api/#minify
                // Note: the `minify` options is true by default (and override other `minify*` options), so if you want to disable the `minifyIdentifiers` option (or other `minify*` options) please use:
                // terserOptions: {
                //   minify: false,
                //   minifyWhitespace: true,
                //   minifyIdentifiers: false,
                //   minifySyntax: true,
                // },
                terserOptions: {},
            }),
        ]
    };
    return config;
};