Passed
Push — v1 ( e71600...3d3d51 )
by Andrew
14:47 queued 06:27
created

webpack.dev.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
dl 0
loc 18
c 0
b 0
f 0
rs 9.352
nop 1
1
// webpack.dev.js - developmental builds
2
const LEGACY_CONFIG = 'legacy';
3
const MODERN_CONFIG = 'modern';
4
5
// node modules
6
const path = require('path');
7
8
// webpack plugins
9
const merge = require('webpack-merge');
10
const webpack = require('webpack');
11
12
// config files
13
const pkg = require('./package.json');
14
const common = require('./webpack.common.js');
15
16
// Configure the webpack-dev-server
17
const configureDevServer = (buildType) => {
0 ignored issues
show
Unused Code introduced by
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...
18
    return {
19
        contentBase: './web',
20
        host: '0.0.0.0',
21
        public: pkg.paths.dist.devPublic,
22
        https: false,
23
        hot: true,
24
        hotOnly: true,
25
        overlay: true,
26
        stats: 'errors-only',
27
        watchOptions: {
28
            poll: true
29
        },
30
        headers: {
31
            'Access-Control-Allow-Origin': '*'
32
        }
33
    };
34
};
35
36
// Postcss loader
37
const configurePostcssLoader = (buildType) => {
38
    // Don't generate CSS for the legacy config in development
39
    if (buildType === LEGACY_CONFIG) {
40
        return {
41
            test: /\.(pcss|css)$/,
42
            loader: 'ignore-loader'
43
        };
44
    }
45
    if (buildType === MODERN_CONFIG) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if buildType === MODERN_CONFIG is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
46
        return {
47
            test: /\.(pcss|css)$/,
48
            use: [
49
                {
50
                    loader: 'style-loader',
51
                },
52
                {
53
                    loader: 'css-loader',
54
                    options: {
55
                        importLoaders: 2,
56
                        sourceMap: true
57
                    }
58
                },
59
                {
60
                    loader: 'resolve-url-loader'
61
                },
62
                {
63
                    loader: 'postcss-loader',
64
                    options: {
65
                        sourceMap: true
66
                    }
67
                }
68
            ]
69
        };
70
    }
71
};
72
73
// Development module exports
74
module.exports = [
75
    merge(
76
        common.legacyConfig,
77
        {
78
            output: {
79
                filename: path.join('./js', '[name]-legacy.[hash].js'),
80
                publicPath: pkg.paths.dist.devPublic + '/',
81
            },
82
            mode: 'development',
83
            devtool: 'inline-source-map',
84
            devServer: configureDevServer(LEGACY_CONFIG),
85
            module: {
86
                rules: [
87
                    configurePostcssLoader(LEGACY_CONFIG),
88
                ],
89
            },
90
            plugins: [
91
                new webpack.HotModuleReplacementPlugin()
92
            ],
93
        }
94
    ),
95
    merge(
96
        common.modernConfig,
97
        {
98
            output: {
99
                filename: path.join('./js', '[name].[hash].js'),
100
                publicPath: pkg.paths.dist.devPublic + '/',
101
            },
102
            mode: 'development',
103
            devtool: 'inline-source-map',
104
            devServer: configureDevServer(MODERN_CONFIG),
105
            module: {
106
                rules: [
107
                    configurePostcssLoader(MODERN_CONFIG),
108
                ],
109
            },
110
            plugins: [
111
                new webpack.HotModuleReplacementPlugin()
112
            ],
113
        }
114
    ),
115
];
116