-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
65 lines (63 loc) · 2.08 KB
/
rollup.config.mjs
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
import { nodeResolve } from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import terser from "@rollup/plugin-terser";
import copy from "@guanghechen/rollup-plugin-copy";
import {injectManifest, getManifest} from "workbox-build";
/** @type {import("rollup").PluginImpl} */
function serviceWorkerPlugin() {
return {
name: "service-worker",
buildStart() { this.addWatchFile("js/serviceWorker.js"); },
async writeBundle(options) {
let buildDir = options.dir;
let rollupEntries = (await getManifest({
globDirectory: buildDir,
globPatterns: ["magicPuddle.js"],
})).manifestEntries;
let homeRollupPlugin = options.plugins.find( ({name}) => name == "homeRollup" );
if (homeRollupPlugin) {
rollupEntries.push(...homeRollupPlugin.api.externalFileUrls);
}
await injectManifest({
swSrc: "js/serviceWorker.js",
swDest: buildDir + "/serviceWorker.js",
globDirectory: ".",
globPatterns: ["*.{html,woff,svg,css}", "app.webmanifest"],
dontCacheBustURLsMatching: /\.v\d/,
manifestTransforms: [(manifest) => {
let htmlEntry = manifest.find( ({url}) => url.includes("MagicPuddle.html") );
htmlEntry.url = ".";
return {manifest};
}],
additionalManifestEntries: rollupEntries,
});
},
}
}
export default async function buildJs({configSite: site}) {
/** @type {import('rollup').RollupOptions} */
var rollupOptions = {
input: "js/magicPuddle.mjs",
plugins: [
(site == "home") && (await import("../../homeRollup.mjs")).default(),
nodeResolve({ browser: true }),
replace({SITE: `"${site}"`}),
(site != "home") && copy({targets: [
{ src: "MagicPuddle.html", rename: "index.html", dest: "build" },
{ src: ["*.{woff,svg,css}"], dest: "build" }
]}),
(site == "glitch") && copy({targets: [
{ src: ["app.webmanifest", "screenshot.png"], dest: "build" }
]}),
terser(),
(site != "itch") && serviceWorkerPlugin(),
],
output: {
dir: (site == "home") ? "." : "build",
sourcemap: site != "itch",
sourcemapExcludeSources: true,
generatedCode: "es2015",
},
};
return rollupOptions;
}