Skip to content

Commit 635f148

Browse files
committed
Simplify build process
1 parent f3e6fcd commit 635f148

4 files changed

Lines changed: 38 additions & 47 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"scripts": {
1919
"dev": "vite",
20-
"build": "vite build && vite build --mode injected",
20+
"build": "vite build",
2121
"lint": "eslint .",
2222
"preview": "vite preview",
2323
"prettier:format": "prettier --write .",

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"web_accessible_resources": [
2121
{
22-
"resources": ["injected.js"],
22+
"resources": ["injected.js", "assets/serialization.js"],
2323
"matches": ["<all_urls>"]
2424
}
2525
],

src/content/content.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ window.addEventListener("message", (event) => {
8383
function injectScript() {
8484
const script = document.createElement("script");
8585
script.src = chrome.runtime.getURL("injected.js");
86+
script.type = "module";
8687
script.onload = () => {
8788
script.remove();
8889
};

vite.config.ts

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,41 @@
11
import { defineConfig } from "vite";
22
import react from "@vitejs/plugin-react-swc";
33
import tailwindcss from "@tailwindcss/vite";
4-
import { resolve } from "path";
54

6-
// https://vite.dev/config/
7-
export default defineConfig(({ mode }) =>
8-
mode === "injected"
9-
? {
10-
build: {
11-
emptyOutDir: false,
12-
lib: {
13-
entry: resolve(__dirname, "src/injected/injected.ts"),
14-
name: "injected",
15-
fileName: () => "injected.js",
16-
formats: ["iife"],
17-
},
18-
rollupOptions: {
19-
output: {
20-
extend: true,
21-
},
22-
},
23-
},
24-
}
25-
: {
26-
plugins: [react(), tailwindcss()],
27-
build: {
28-
rollupOptions: {
29-
input: {
30-
// DevTools panel (React app)
31-
panel: "index.html",
32-
// DevTools entry point
33-
devtools: "devtools.html",
34-
// Content script
35-
content: "src/content/content.ts",
36-
// Background service worker
37-
background: "src/background/background.ts",
38-
},
39-
output: {
40-
entryFileNames: (chunkInfo) => {
41-
if (chunkInfo.name === "content") return "content.js";
42-
if (chunkInfo.name === "background") return "background.js";
43-
return "assets/[name]-[hash].js";
44-
},
45-
chunkFileNames: "assets/[name]-[hash].js",
46-
assetFileNames: "assets/[name]-[hash].[ext]",
47-
},
48-
},
5+
export default defineConfig({
6+
plugins: [react(), tailwindcss()],
7+
build: {
8+
rollupOptions: {
9+
input: {
10+
// DevTools panel (React app)
11+
panel: "index.html",
12+
// DevTools entry point
13+
devtools: "devtools.html",
14+
// Content script
15+
content: "src/content/content.ts",
16+
// Background service worker
17+
background: "src/background/background.ts",
18+
injected: "src/injected/injected.ts",
19+
},
20+
output: {
21+
entryFileNames: (chunkInfo) => {
22+
switch (chunkInfo.name) {
23+
case "content":
24+
return "content.js";
25+
case "background":
26+
return "background.js";
27+
case "injected":
28+
return "injected.js";
29+
default:
30+
return "assets/[name]-[hash].js";
31+
}
4932
},
33+
chunkFileNames: ({ name }) =>
34+
name === "serialization"
35+
? "assets/serialization.js"
36+
: "assets/[name]-[hash].js",
37+
assetFileNames: "assets/[name]-[hash].[ext]",
5038
},
51-
);
39+
},
40+
},
41+
});

0 commit comments

Comments
 (0)