-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
41 lines (40 loc) · 1.14 KB
/
rollup.config.js
File metadata and controls
41 lines (40 loc) · 1.14 KB
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
import { terser } from "rollup-plugin-terser";
import css from "rollup-plugin-css-only";
import copy from "rollup-plugin-copy";
import { promises as fs } from "fs";
export default {
input: "build/dist/index.js",
output: {
format: "iife",
name: "app",
dir: "dist/",
assetFileNames: "built/[name]-[hash][extname]",
entryFileNames: "built/[name]-[hash].js"
},
plugins: [
css({ output: "bundle.css" }),
copy({
targets: [{ src: "public/*", dest: "dist" }]
}),
terser(),
{
async generateBundle(options, bundle) {
const entrypoint = Object.keys(bundle)[0];
let html = await fs.readFile("./public/index.html", "utf8");
let css = await fs.readFile("./build/dist/global.css", "utf8");
html = html.replace("/dist/index.js", `/${entrypoint}`);
const ref = this.emitFile({
type: "asset",
name: "global.css",
source: css
});
html = html.replace("/dist/global.css", `/${this.getFileName(ref)}`);
this.emitFile({
type: "asset",
fileName: "index.html",
source: html
});
}
}
]
};