-
Notifications
You must be signed in to change notification settings - Fork 19
/
rollup.config.mjs
88 lines (86 loc) · 2.04 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import cjs from "rollup-plugin-cjs-es";
import resolve from "@rollup/plugin-node-resolve";
import {copy} from '@web/rollup-plugin-copy';
import shim from "rollup-plugin-shim";
import iife from "rollup-plugin-iife";
import terser from "@rollup/plugin-terser";
import output from "rollup-plugin-write-output";
import json from "@rollup/plugin-json";
import glob from "tiny-glob";
export default async () => ({
input: await glob("src/*.js"),
output: {
format: "es",
dir: "build",
sourcemap: true
},
plugins: [
shim({
path: `
export function basename(s) {
const parts = s.split(/[\\/]/);
return parts[parts.length - 1];
}
`,
"safe-buffer": `
export class Buffer {
constructor(s) {
this.s = s;
}
static from(binary) {
return new Buffer(binary);
}
toString() {
const bytes = new Uint8Array(this.s.length);
for (let i = 0; i < this.s.length; i++) {
bytes[i] = this.s.charCodeAt(i);
}
return new TextDecoder("utf-8").decode(bytes);
}
}
`
}),
resolve({
exportConditions: [
'node'
]
}),
json(),
cjs({
nested: true
}),
copy({
patterns: "**/*",
rootDir: "src/static"
}),
iife(),
terser({
module: false
}),
output([
{
test: /background\.js$/,
target: "build/manifest.json",
handle: (json, {scripts}) => {
json.background.scripts = scripts;
return json;
}
},
{
test: /content\.js$/,
target: "build/manifest.json",
handle: (json, {scripts}) => {
json.content_scripts[0].js = scripts;
return json;
}
},
{
test: /(dialog|options|picker)\.js$/,
target: "build/$1.html",
handle: (content, {htmlScripts}) => {
return content.replace("</body>", `${htmlScripts}\n</body>`);
}
}
])
]
});