-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
129 lines (127 loc) · 3.31 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { exec } from "child_process";
import svelte from "rollup-plugin-svelte";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import preprocess from "svelte-preprocess";
import postcss from "rollup-plugin-postcss";
import autoprefixer from "autoprefixer";
import tailwindcss from "tailwindcss";
import os from "os";
import fs from "fs";
const production = !process.env.ROLLUP_WATCH;
const buildEnv = process.env.BUILD_ENV;
function serve() {
return {
writeBundle() {
// Open Brave browser with the specified URL
if (production) {
const manifestSource =
buildEnv === "firefox"
? "public/manifests/manifest_firefox.json"
: "public/manifests/manifest_chrome.json";
const manifestDest = "public/manifest.json";
fs.copyFileSync(manifestSource, manifestDest);
} else {
let command;
if (os.platform() === "linux") {
command = "brave-browser --reload-extension=public/build";
} else {
command =
"'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser' --reload-extension=public/build";
}
// Open Brave browser with the specified URL
exec(command, (err) => {
if (err) {
console.error("Failed to open Brave:", err);
}
});
}
},
};
}
function buildConfig(inputFileName, outputFileName) {
return {
input: `src/${inputFileName}.ts`,
output: {
file: `public/build/${outputFileName}.js`,
format: "iife",
name: "app",
sourcemap: !production,
},
plugins: [
svelte({
compilerOptions: {
dev: !production,
},
preprocess: preprocess({
typescript: {
tsconfigFile: "./tsconfig.app.json",
},
postcss: {
plugins: [tailwindcss, autoprefixer],
},
}),
}),
postcss({
extract: `${outputFileName}.css`,
minimize: production,
sourceMap: !production,
config: {
path: "./postcss.config.cjs",
},
}),
typescript({ sourceMap: !production, tsconfig: "./tsconfig.app.json" }),
resolve({ browser: true }),
commonjs(),
],
watch: {
clearScreen: false,
},
};
}
export default [
buildConfig("popup", "popup"),
buildConfig("dashboard", "dashboard"),
{
input: "src/scripts/background.ts",
output: {
format: buildEnv === "firefox" ? "iife" : "es",
name: "background",
file: "public/background.js",
sourcemap: !production,
},
plugins: [
typescript({
tsconfig: "./tsconfig.background.json",
sourceMap: !production,
}),
commonjs(),
resolve({ browser: true, preferBuiltins: false }),
serve(),
],
watch: {
clearScreen: false,
},
},
{
input: "src/scripts/content.ts",
output: {
format: "iife",
name: "content",
file: "public/content.js",
sourcemap: !production,
},
plugins: [
typescript({
tsconfig: "./tsconfig.background.json",
}),
commonjs(),
resolve({ browser: true, preferBuiltins: false }),
serve(),
],
watch: {
clearScreen: false,
},
},
];