Passed
Pull Request — v3 (#436)
by Ben
07:13
created

webpack.dev.js (2 issues)

Severity
1
// node modules
2
const merge = require('webpack-merge');
3
const path = require('path');
4
const webpack = require('webpack');
5
6
// webpack plugins
7
const DashboardPlugin = require('webpack-dashboard/plugin');
8
9
// config files
10
const common = require('./webpack.common.js');
11
const pkg = require('./package.json');
0 ignored issues
show
The constant pkg seems to be never used. Consider removing it.
Loading history...
12
const settings = require('./webpack.settings.js');
13
14
// Configure the webpack-dev-server
15
const configureDevServer = (buildType) => {
0 ignored issues
show
The parameter buildType is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
16
    return {
17
        public: settings.devServerConfig.public(),
18
        contentBase: path.resolve(__dirname, settings.paths.templates),
19
        host: settings.devServerConfig.host(),
20
        port: settings.devServerConfig.port(),
21
        https: !!parseInt(settings.devServerConfig.https()),
22
        disableHostCheck: true,
23
        hot: true,
24
        overlay: true,
25
        watchContentBase: true,
26
        watchOptions: {
27
            poll: !!parseInt(settings.devServerConfig.poll()),
28
            ignored: /node_modules/,
29
        },
30
        headers: {
31
            'Access-Control-Allow-Origin': '*'
32
        },
33
    };
34
};
35
36
// Configure Image loader
37
const configureImageLoader = () => {
38
    return {
39
        test: /\.(png|jpe?g|gif|svg|webp)$/i,
40
        use: [
41
            {
42
                loader: 'file-loader',
43
                options: {
44
                    name: 'img/[name].[ext]'
45
                }
46
            }
47
        ]
48
    };
49
};
50
51
// Configure optimization
52
const configureOptimization = () => {
53
    return {
54
        splitChunks: {
55
            cacheGroups: {
56
            }
57
        },
58
    };
59
};
60
61
// Configure the Postcss loader
62
const configurePostcssLoader = () => {
63
    return {
64
        test: /\.(pcss|css)$/,
65
        use: [
66
            {
67
                loader: 'style-loader',
68
            },
69
            {
70
                loader: 'vue-style-loader',
71
            },
72
            {
73
                loader: 'css-loader',
74
                options: {
75
                    importLoaders: 2,
76
                    sourceMap: true
77
                }
78
            },
79
            {
80
                loader: 'resolve-url-loader'
81
            },
82
            {
83
                loader: 'postcss-loader',
84
                options: {
85
                    sourceMap: true
86
                }
87
            }
88
        ]
89
    };
90
};
91
92
// Development module exports
93
module.exports = [
94
    merge(
95
        common.legacyConfig,
96
        {
97
            output: {
98
                filename: path.join('./js', '[name].js'),
99
                publicPath: settings.devServerConfig.public() + '/',
100
            },
101
            resolve: {
102
                alias: {
103
                    'vue$': 'vue/dist/vue.js'
104
                }
105
            },
106
            mode: 'development',
107
            devtool: 'inline-source-map',
108
            optimization: configureOptimization(),
109
            devServer: configureDevServer(),
110
            module: {
111
                rules: [
112
                    configurePostcssLoader(),
113
                    configureImageLoader(),
114
                ],
115
            },
116
            plugins: [
117
                new webpack.HotModuleReplacementPlugin(),
118
                new DashboardPlugin(),
119
            ],
120
        }
121
    ),
122
];
123