-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_rollup.mjs
More file actions
63 lines (61 loc) · 1.61 KB
/
Copy path_rollup.mjs
File metadata and controls
63 lines (61 loc) · 1.61 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import terser from "@rollup/plugin-terser";
import path from "path";
import fs from "fs";
import del from "rollup-plugin-delete";
import generatePackageJson from "rollup-plugin-generate-package-json";
import styles from "rollup-plugin-styles";
import ts from "rollup-plugin-ts";
import { fileURLToPath } from "url";
export function embeddedWorkerPlugin() {
return {
name: "embedded-worker",
async resolveId(source, importer) {
if (source.endsWith("?worker")) {
return { id: path.join(path.dirname(fileURLToPath(import.meta.url)), "node_modules", source) };
}
},
async load(id) {
if (id.endsWith("?worker")) {
const file = id.substring(0, id.lastIndexOf("?"));
const content = fs.readFileSync(file).toString("base64");
return {
code: `export default "data:text/javascript;base64,${content}";`,
};
}
},
};
}
export default (
dir,
input,
pkg
) => ({
input,
output: [
{
dir: "dist/" + dir,
entryFileNames: "[name].js",
format: "esm",
},
],
context: "window",
plugins: [
del({ targets: "dist/" + dir + "/*" }),
embeddedWorkerPlugin(),
styles(),
json(),
ts(),
nodeResolve({ browser: true }),
commonjs(),
replace({
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify("production"),
}),
terser(),
generatePackageJson({ baseContents: pkg }),
],
});