-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
85 lines (80 loc) · 2.01 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
73
74
75
76
77
78
79
80
81
82
83
84
85
require("dotenv").config();
import { terser } from "rollup-plugin-terser";
import html from "@rollup/plugin-html";
import postcss from "rollup-plugin-postcss";
import replace from "@rollup/plugin-replace";
import resolve from "@rollup/plugin-node-resolve";
import svelte from "rollup-plugin-svelte";
import sveltePreprocess from "svelte-preprocess";
const production = process.env.NODE_ENV === "production";
export default [
{
name: "inject",
input: "src/inject/inject.js",
},
{
name: "popup",
input: "src/page_action/popup.js",
html: "src/page_action/page_action.html",
},
].map((entry, index) => ({
input: entry.input,
output: {
dir: "dist",
format: "iife",
},
plugins: [
svelte({
preprocess: sveltePreprocess({ postcss: true }),
dev: !production,
emitCss: true,
css: false,
}),
resolve({
browser: true,
dedupe: ["svelte"],
}),
replace({
"process.env.NODE_ENV": JSON.stringify(
production ? "production" : "development"
),
...Object.keys(process.env).reduce((sum, key) => {
sum[`process.env.${key}`] = JSON.stringify(process.env[key]);
return sum;
}, {}),
}),
postcss({
extract: true,
}),
production && terser(),
entry.html &&
html({
fileName: `${entry.name}.html`,
title: "body",
template: ({ attributes, bundle, files, publicPath, title }) => {
const scripts = (files.js || [])
.map(({ fileName }) => {
return `<script src="${publicPath}${fileName}"></script>`;
})
.join("\n");
const links = (files.css || [])
.map(({ fileName }) => {
return `<link href="${publicPath}${fileName}" rel="stylesheet">`;
})
.join("\n");
return `<!doctype html>
<html>
<head>
<title>${title}</title>
${links}
</head>
<body>
<div id="main-popup">
</div>
${scripts}
</body>
</html>`;
},
}),
],
}));