-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
72 lines (64 loc) · 1.63 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
68
69
70
71
72
import { env } from "node:process";
import terser from "@rollup/plugin-terser";
import replace from "@rollup/plugin-replace";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import asset from "./rollup/asset.js";
import htmlEntry from "./rollup/html.js";
import manifest from "./rollup/manifest.js";
import copy from "./rollup/copy.js";
import postcss from "./rollup/postcss.js";
import svg from "./rollup/svg.js";
import template from "./rollup/template.js";
import { packBundle, packSources } from "./rollup/pack.js";
const isProduction = env.NODE_ENV === "production";
const addonZipName = `${env.npm_package_name}-${env.npm_package_version}.zip`;
function minifyJson(source, { path }) {
if (/\.json$/.test(path)) {
return JSON.stringify(JSON.parse(source.data));
}
}
export default {
// Avoid generate the "facade" entry chunk.
preserveEntrySignatures: false,
input: "manifest.json?webext",
output: {
generatedCode: "es2015",
dir: "dist",
chunkFileNames: "[name].js",
},
plugins: [
replace({
"import.meta.env.DEV": `${!isProduction}`,
"typeof window": "'object'",
}),
asset({
loaders: [
postcss,
svg,
isProduction && minifyJson,
],
source: {
include: ["components/**/*.css", "**/*.svg"],
},
url: {
include: ["**/*.{ico,png,jpg}"],
},
}),
nodeResolve(),
copy({
context: "locales",
from: "**/*",
to: "_locales",
toDirectory: true,
}),
manifest(),
htmlEntry(),
template(),
isProduction && terser(),
env.PACK && packBundle(addonZipName, true),
env.PACK && packSources(
`source-${env.npm_package_version}.zip`,
["/chrome", "/doc"],
),
],
};