Completed
Push — develop ( 954c6c...e73990 )
by
unknown
02:36
created

webpack.config.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 1
rs 10
1
const webpack = require('webpack');
2
const { join, resolve } = require('path');
3
const { getIfUtils, removeEmpty } = require('webpack-config-utils');
4
const ExtractTextPlugin = require('extract-text-webpack-plugin');
5
const AssetsPlugin = require('assets-webpack-plugin')
6
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
7
const WriteFilePlugin = require('write-file-webpack-plugin');
8
9
module.exports = (env) => {
10
    const { ifProd, ifNotProd } = getIfUtils(env);
11
12
    return {
13
        context: resolve(__dirname, './app/Resources/assets'),
14
        devtool: ifProd('source-map', 'cheap-module-source-map'),
15
        entry: {
16
            main: './main.js'
17
        },
18
        output: {
19
            path: resolve(__dirname, './web'),
20
            filename: ifProd('js/[name].[hash].js', 'js/[name].js'),
21
            pathinfo: ifNotProd(), // Include comments with information about the modules.
22
        },
23
        resolve: {
24
            extensions: ['.js'],
25
        },
26
        module: {
27
            rules: [
28
                {
29
                    test: require.resolve('jquery'),
30
                    use: [
31
                        {
32
                            loader: 'expose-loader',
33
                            query: 'jQuery'
34
                        },
35
                        {
36
                            loader: 'expose-loader',
37
                            query: '$'
38
                        }
39
                    ]
40
                },
41
                {
42
                    // Do not transform vendor's CSS with CSS-modules
43
                    // The point is that they remain in global scope.
44
                    test: /\.css$/,
45
                    include: /node_modules/,
46
                    loader: ifNotProd(
47
                        [
48
                            'style-loader',
49
                            {
50
                                loader: 'css-loader',
51
                                query: { sourceMap: true, }
52
                            }
53
                        ],
54
                        ExtractTextPlugin.extract({
55
                            fallbackLoader: 'style-loader',
56
                            loader: [
57
                                {
58
                                    loader: 'css-loader',
59
                                    // @TODO replace with "options" when ExtractTextPlugin is fixed
60
                                    query: {
61
                                        minimize: true,
62
                                    }
63
                                }
64
                            ],
65
66
                        })
67
                    )
68
                },
69
                {
70
                    test: /\.(woff(2)?|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
71
                    use: 'file-loader?name=fonts/[name].[hash].[ext]'
72
                },
73
                {
74
                    test: /\.(gif|png|jpe?g|svg)$/i,
75
                    use: removeEmpty(
76
                        [
77
                            {
78
                                loader: 'url-loader',
79
                                query: {
80
                                    limit: 10 * 1000, // byte limit in bytes ( 10kb )
81
                                    hashType: 'sha512',
82
                                    digestType: 'hex',
83
                                    name: 'images/[name].[hash].[ext]',
84
                                }
85
                            },
86
                            ifProd(
87
                                {
88
                                    loader: 'image-webpack-loader',
89
                                    query: {
90
                                        progressive: true,
91
                                        optimizationLevel: 7,
92
                                        interlaced: false,
93
                                        pngquant: {
94
                                            quality: '65-90',
95
                                            speed: 4
96
                                        }
97
                                    }
98
                                }
99
                            )
100
                        ]
101
                    )
102
                },
103
            ]
104
        },
105
        plugins: removeEmpty([
106
            // write files to fs with webpack-dev-server
107
            new WriteFilePlugin(),
108
            new webpack.optimize.CommonsChunkPlugin({
109
                name: 'vendor',
110
                fileName: 'vendor.js',
111
                chunks: ['main'],
112
                minChunks: module => /node_modules\//.test(module.resource)
113
            }),
114
            ifProd(new ExtractTextPlugin({
115
                filename: 'css/[name].[contenthash].css',
116
                allChunks: true,
117
            })),
118
            ifProd(
119
                new AssetsPlugin({ path: join(__dirname, 'web', 'bundles') })
120
            ),
121
            ifProd(new webpack.optimize.UglifyJsPlugin({
122
                compress: {
123
                    screw_ie8: true,
124
                    warnings: false,
125
                },
126
                output: { comments: false }
127
            })),
128
            new webpack.optimize.CommonsChunkPlugin({
129
                name: 'vendor',
130
                minChunks: Infinity,
131
            }),
132
            new ProgressBarPlugin(),
133
        ]),
134
    };
135
}
136