aboutsummaryrefslogtreecommitdiff
path: root/juick-server/webpack.config.js
blob: 8057ec15ab6e455016620b0b63c8c23f2341de07 (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
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const StyleLintPlugin = require('stylelint-webpack-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/es6.promise',
                'whatwg-fetch',
                __dirname + '/src/main/assets/scripts.js',
                require.resolve('evil-icons/assets/evil-icons.js')
            ],
            'style': [
                __dirname + '/src/main/assets/style.css',
                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: [
                        MiniCssExtractPlugin.loader,
                        {
                            loader: 'css-loader'
                        },
                        {
                            loader: 'postcss-loader', options: {
                                plugins: () => [
                                    require('autoprefixer')({})
                                ]
                            }
                        }
                    ]
                },
                { test: /\.png$/, loader: 'url-loader?limit=10000000000' },
                { test: /\.svg$/, loader: 'url-loader?limit=10000000000' }
            ]
        },
        plugins: [
            new StyleLintPlugin({ configFile: '.stylelintrc.json', context: 'src/main/assets', files: ['**/*.css'], emitErrors: false }),
            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;
};