-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
executable file
·89 lines (82 loc) · 2.51 KB
/
webpack.config.js
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
const Encore = require('@symfony/webpack-encore'),
CompressionPlugin = require('compression-webpack-plugin'),
workboxPlugin = require('workbox-webpack-plugin'),
config = require('./webpack-config.json');
Encore.setOutputPath(config.outputPath)
.setPublicPath(config.publicPath)
.cleanupOutputBeforeBuild()
.autoProvidejQuery()
.enableSassLoader()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(true);
Object.keys(config.scripts).forEach(key => {
let script = config.scripts[key];
Encore
.addEntry(script.dest, script.src);
});
Object.keys(config.styles).forEach(key => {
let style = config.styles[key];
Encore
.addStyleEntry(style.dest, style.src);
});
Encore
.copyFiles({
from: config.copy.from,
to: config.copy.to
})
.splitEntryChunks()
.enableSingleRuntimeChunk()
.configureSplitChunks(splitChunks => {
splitChunks.minSize = 0;
})
.configureBabel((config) => {
config.plugins.push('@babel/plugin-proposal-class-properties');
})
// enables @babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
.enableBuildNotifications();
if (Encore.isProduction()) {
Encore
.addPlugin(
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js|css)$/
}),
10
)
.addPlugin(
new workboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: new RegExp('/assets/images/(.*)'),
handler: 'CacheFirst'
},
{
urlPattern: new RegExp('/media/(.*)'),
handler: 'CacheFirst'
},
{
urlPattern: new RegExp('/de/(.*)'),
handler: 'NetworkFirst'
},
{
urlPattern: new RegExp('/en/(.*)'),
handler: 'NetworkFirst'
}
],
swDest: config.swDest
})
)
;
}
// https://github.com/symfony/webpack-encore/issues/191#issuecomment-340377542
const webpackConfig = Encore.getWebpackConfig();
webpackConfig.watchOptions = {
poll: true
};
module.exports = webpackConfig;