-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrollup.config.mjs
45 lines (44 loc) · 1.19 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
import html from "@rollup/plugin-html"
import json from "@rollup/plugin-json"
import { nodeResolve } from "@rollup/plugin-node-resolve"
import { readFile } from "fs/promises"
import { defineRollupSwcOption, swc } from "rollup-plugin-swc3"
export default {
input: "src/index.jsx",
output: {
dir: "dist",
entryFileNames: "[name].[hash].js",
},
plugins: [
html({
fileName: "index.html",
template: async ({ files }) => {
const content = await readFile("src/index.html", { encoding: "utf8" })
const fileName = files.js.find(({ name }) => name === "index").fileName
return content
.replace(
"{preload}",
`<link rel="modulepreload" as="script" href="${fileName}" />`,
)
.replace("{js}", `<script type="module" src="${fileName}"></script>`)
},
}),
nodeResolve(),
json(),
swc(
defineRollupSwcOption({
jsc: {
target: "es2021",
transform: {
react: {
pragma: "h",
pragmaFrag: "Fragment",
importSource: "preact",
runtime: "automatic",
},
},
},
}),
),
],
}