This repository was archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathwebpack.config.js
More file actions
175 lines (160 loc) · 4.08 KB
/
webpack.config.js
File metadata and controls
175 lines (160 loc) · 4.08 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const isdev = require('isdev')
const webpack = require('webpack')
const ESLintPlugin = require('eslint-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const vueRule = require('./rules/vue')
const sassRule = require('./rules/sass')
const fontsRule = require('./rules/fonts')
const imagesRule = require('./rules/images')
const javascriptRule = require('./rules/javascript')
const externalFontsRule = require('./rules/external.fonts')
const externalImagesRule = require('./rules/external.images')
const config = require('./app.config')
module.exports = {
/**
* Should the source map be generated?
*
* @type {string|undefined}
*/
devtool: (isdev && config.settings.sourceMaps) ? 'source-map' : undefined,
/**
* Providing the mode configuration option tells webpack to use its built-in optimizations accordingly.
*
* @type {string|undefined}
*/
mode: isdev ? 'development' : 'production',
/**
* Application entry files for building.
*
* @type {Object}
*/
entry: config.assets,
/**
* Output settings for application scripts.
*
* @type {Object}
*/
output: {
path: config.paths.public,
filename: config.outputs.javascript.filename
},
/**
* External objects which should be accessible inside application scripts.
*
* @type {Object}
*/
externals: config.externals,
/**
* Custom modules resolving settings.
*
* @type {Object}
*/
resolve: config.resolve,
/**
* Performance settings to speed up build times.
*
* @type {Object}
*/
performance: {
hints: false
},
/**
* Build rules to handle application assset files.
*
* @type {Object}
*/
module: {
rules: [
vueRule,
sassRule,
fontsRule,
imagesRule,
javascriptRule,
externalFontsRule,
externalImagesRule,
]
},
/**
* Common plugins which should run on every build.
*
* @type {Array}
*/
plugins: [
new ESLintPlugin(),
new VueLoaderPlugin(),
new webpack.LoaderOptionsPlugin({ minimize: !isdev }),
new MiniCssExtractPlugin({
filename: config.outputs.css.filename,
}),
new CleanWebpackPlugin({ verbose: true }),
new CopyPlugin({
patterns: [
{
from: `${config.paths.images}/**/*`,
to: config.outputs.image.filename,
noErrorOnMissing: true,
},
],
}),
]
}
/**
* Adds Stylelint plugin if
* linting is configured.
*/
if (config.settings.styleLint) {
module.exports.plugins.push(
new StyleLintPlugin(config.settings.styleLint)
)
}
/**
* Adds BrowserSync plugin when
* settings are configured.
*/
if (config.settings.browserSync) {
module.exports.plugins.push(
new BrowserSyncPlugin(config.settings.browserSync, {
// Prevent BrowserSync from reloading the page
// and let Webpack Dev Server take care of this.
reload: false
})
)
}
/**
* Adds optimalizing plugins when
* generating production build.
*/
if (! isdev) {
module.exports.plugins.push(
new ImageMinimizerPlugin({
minimizerOptions: {
// Lossless optimization with custom option
// Feel free to experiment with options for better result for you
plugins: [
['gifsicle', { interlaced: true, optimizationLevel: 3 }],
['jpegtran', { progressive: true }],
['optipng', { optimizationLevel: 7 }],
['pngquant', { quality: '65-90', speed: 4 }],
[
'svgo',
{
plugins: [
{
removeViewBox: false,
removeUnknownsAndDefaults: false,
cleanupIDs: false
},
],
},
],
],
},
}),
)
}