-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
94 lines (90 loc) · 2.3 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
90
91
92
93
94
import fs from "fs";
import path from "path";
import WorkerUrlPlugin from "worker-url/plugin.js";
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
import WorkboxPlugin from "workbox-webpack-plugin";
import crypto from "crypto";
import { globSync } from "glob";
const __dirname = path.dirname(new URL(import.meta.url).pathname);
const outputPath = path.resolve(__dirname, "public");
const cacheId = "msxplay";
const getRevision = (file) => {
const buffer = fs.readFileSync(file);
return crypto.createHash("md5").update(buffer).digest("hex");
}
const getManifestEntry = (file) => {
return {
url: path.relative(outputPath, file),
revision: getRevision(file),
};
};
const additionalManifestEntries = [
"https://cdnjs.cloudflare.com/ajax/libs/ace/1.31.2/ace.min.js",
path.resolve(outputPath, "editor.html"),
path.resolve(outputPath, "demo/blank.mml"),
path.resolve(outputPath, "demo/grider.mml"),
path.resolve(outputPath, "demo/grider.mgs"),
...globSync(path.resolve(outputPath, "css/*.css")),
...globSync(path.resolve(outputPath, "js/*.js")),
].map((file) => {
if (file.startsWith("https:")) {
return { url: file, revision: null };
}
return getManifestEntry(file);
});
export default {
mode: "production",
context: __dirname + "/src",
entry: {
"msxplay-bundle": "./entry.js",
},
// devtool: "source-map",
experiments: {
outputModule: true,
},
output: {
//publicPath: "/dist/",
path: outputPath,
filename: "dist/[name].js",
library: {
type: "module",
},
},
resolve: {
fallback: {
fs: false,
path: false,
},
},
optimization: {
splitChunks: {
minChunks: 9999, // prevent to split chunk
},
},
plugins: [
new WorkerUrlPlugin(),
new WorkboxPlugin.GenerateSW({
cacheId: cacheId,
cleanupOutdatedCaches: true,
clientsClaim: true,
skipWaiting: true,
swDest: path.resolve(outputPath, "sw.js"),
additionalManifestEntries,
runtimeCaching: [
{
handler: "NetworkFirst",
urlPattern: /\.(jpe?g|png|mml)$/,
options: {
cacheName: cacheId + "-asset-cache",
},
},
],
}),
/*, new BundleAnalyzerPlugin()*/
],
stats: {
modules: false,
children: false,
entrypoints: false,
},
};