aboutsummaryrefslogtreecommitdiff
path: root/webpack.config.js
blob: c2d0dd4e6a5cea3873880658ca2d8c5e2f447b9e (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const CopyPlugin = require('copy-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',
                __dirname + '/src/main/assets/scripts.js',
                __dirname + '/src/main/assets/style.css',
                'evil-icons/assets/evil-icons.css'
            ]
        },
        output: {
            path: __dirname + '/src/main/resources/static',
            filename: '[name].js'
        },
        module: {
            rules: [
                { test: /\.js$/, loader: 'babel-loader' },
                {
                    test: /\.css$/,
                    use: [
                        dev ? 'style-loader' : MiniCssExtractPlugin.loader,
                        {
                            loader: 'css-loader',
                            options: {
                                sourceMap: dev
                            }
                        },
                        {
                            loader: 'postcss-loader',
                            options: {
                                postcssOptions: {
                                    plugins: [
                                        'stylelint',
                                        ['postcss-preset-env', { stage: 0 }]
                                    ]
                                }
                            }
                        }
                    ]
                },
                {
                    test: /\.(jpe?g|png|svg|gif)$/i,
                    loader: 'url-loader'
                }
            ]
        },
        plugins: [
            new MiniCssExtractPlugin({ filename: 'style.css' }),
            new ESLintPlugin({ files: 'src/main/assets', lintDirtyModulesOnly: true, failOnWarning: false, failOnError: true, fix: false }),
            new CopyPlugin({
                patterns: [{
                    from: __dirname + '/node_modules/evil-icons/assets/sprite.svg',
                    to: __dirname + '/src/main/resources/static/'
                }],
            }),
        ],
    };
    if (!dev) {
        config.optimization = {
            minimizer: [
                '...',
                new CssMinimizerPlugin({
                    sourceMap: true
                })
            ]
        };
    }
    return config;
};