-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathrollup.config.js
67 lines (64 loc) · 2.07 KB
/
rollup.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
// Import rollup plugins
import html from "@web/rollup-plugin-html";
import { copy } from "@web/rollup-plugin-copy";
import resolve from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import minifyHTML from "rollup-plugin-minify-html-literals";
import summary from "rollup-plugin-summary";
import json from "@rollup/plugin-json";
import typescript from "@rollup/plugin-typescript";
import serve from "rollup-plugin-serve";
import postcss from "rollup-plugin-postcss";
const PROD = !!process.env.PROD;
const WATCH = !!process.env.ROLLUP_WATCH;
const ANALYTICS_SCRIPT = `
<script>
window.addEventListener('hashchange', function(e) {
window.goatcounter.count({
path: location.pathname + location.search + location.hash,
})
})
</script>
<script data-goatcounter="https://eudes.goatcounter.com/count"
async src="//gc.zgo.at/count.js"></script>
`;
export default {
input: "src/web/index.html",
plugins: [
// Entry point for application build; can specify a glob to build multiple
// HTML files for non-SPA app
html({
transformHtml: (html) =>
PROD ? html.replace("</body>", `${ANALYTICS_SCRIPT}</body>`) : html,
}),
// Resolve bare module specifiers to relative paths
resolve(),
json({ compact: true }),
typescript({ tsconfig: "src/web/tsconfig.json" }),
postcss({ minimize: true }),
// Minify HTML template literals
minifyHTML(),
// Minify JS
PROD && terser({ ecma: 2020, module: true, warnings: true }),
// Print bundle summary
summary(),
// Copy any static assets to build directory
copy({
rootDir: "src/web",
patterns: ["assets/**/*"],
}),
copy({
patterns: ["examples/**/*"],
}),
WATCH && serve({ contentBase: "dist", open: true }),
],
output: {
dir: PROD ? "docs" : "dist",
entryFileNames: PROD ? "[name]-[hash].js" : "[name].js",
chunkFileNames: PROD ? "[name]-[hash].js" : "[name].js",
manualChunks: {
"game-data": ["src/game-data/index.ts"],
},
},
preserveEntrySignatures: "strict",
};