-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.client.config.esm.js
95 lines (87 loc) · 3.1 KB
/
webpack.client.config.esm.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
90
91
92
93
94
95
const util = require("../../util");
const path = require("path");
process.env.NODE_CONFIG_DIR = path.join(__dirname, "../../config");
const config = require("config");
const {BundleAnalyzerPlugin} = require("webpack-bundle-analyzer");
const webpackBaseConfig = require("./webpack.client.config.base");
const WorkboxPlugin = require("workbox-webpack-plugin");
const packageJson = require("./package");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const {DefinePlugin} = require("webpack");
const publicPath = `${config.get("www.assetUrl")}/`;
const bundleName = `${config.get("www.bundle.name")}.esm`;
const swBundleName = `${config.get("www.bundle.sw")}.esm`;
const swBundleInstallerName = `${config.get("www.bundle.swInstaller")}.esm`;
const {
isDevelopment
} = util;
const plugins = [];
if (!isDevelopment || process.env.BUNDLE_ANALYZER) {
plugins.push(
new BundleAnalyzerPlugin({
reportFilename: "report.esm.html",
analyzerMode: "static",
openAnalyzer: false
})
);
}
module.exports = webpackBaseConfig({
babelEnv: "client.esm",
// babelJsType: "javascript/esm",
rules: [],
entry: {
[bundleName]: ["raf/polyfill", "materialize-css", path.join(__dirname, "src/public/views/index.jsx")],
[swBundleInstallerName]: ["raf/polyfill", "materialize-css", path.join(__dirname, "src/public/sw/installer.js")],
styles: path.join(__dirname, "./styles/style.scss")
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: util.webpackVendorInclusions,
name: "vendor",
filename: "vendor.esm.js",
chunks: "all"
}
}
},
minimizer:
isDevelopment
? []
: [
new TerserPlugin({
parallel: true,
terserOptions: {
sourceMap: true
}
}),
new OptimizeCSSAssetsPlugin()
]
},
plugins: plugins.concat([
new WorkboxPlugin.GenerateSW({
swDest: `${swBundleName}.js`,
skipWaiting: true,
clientsClaim: true,
offlineGoogleAnalytics: false,
cacheId: packageJson.name,
runtimeCaching: [
{
urlPattern: /.*(?:flickr|instagram|tumblr|unsplash|gravatar)\.com|.*(shields)\.io|.*(crisp)\.chat/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "external",
expiration: {
maxEntries: 100,
purgeOnQuotaError: true
}
}
}
]
}),
new DefinePlugin({
__SW_BUNDLE_PATH__: JSON.stringify(path.join(publicPath, `${swBundleName}.js`))
})
])
});