-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
143 lines (136 loc) · 3.9 KB
/
vite.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { writeFile } from "node:fs/promises";
import { resolve } from "node:path";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { defineConfig } from "vite";
/**
* License banner to be added to the top of your extension's scripts.
* Replace with whatever license you wish to use.
*/
const license_banner = `/*!
Copyright {{YOUR_NAME_OR_COMPANY}}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/`;
export default defineConfig(({ mode }) => {
// mode can be set with '--mode' flag
const dev = mode === "development";
const icon_path = "assets/pin.png";
const service_worker_name = "service_worker";
const content_script_name = "content_script";
const version = "0.0.1";
const minimum_chrome_version = "119";
/** @type {chrome.runtime.ManifestV3} */
const manifest = {
manifest_version: 3,
name: "__MSG_extension_name__",
short_name: "__MSG_extension_short_name__",
description: "__MSG_extension_description__",
version,
version_name: version,
default_locale: "en",
icons: {
16: icon_path,
32: icon_path,
48: icon_path,
128: icon_path,
},
author: {
email: "your_email@any_domain.tld",
},
optional_permissions: ["scripting"],
optional_host_permissions: ["<all_urls>"],
background: {
service_worker: `${service_worker_name}.js`,
type: "module",
},
minimum_chrome_version,
action: {
default_icon: icon_path,
},
/**
* Remove the following if scripts are bundled together.
*/
web_accessible_resources: [
{
matches: ["<all_urls>"],
resources: ["*.js"],
},
],
};
return {
appType: "custom",
plugins: [
svelte({
compilerOptions: {
runes: true,
dev: dev,
css: "injected",
modernAst: true,
},
prebundleSvelteLibraries: true,
}),
{
// This plugin writes the manifest.json file to the output directory.
name: "Chrome Extension Manifest",
async writeBundle(output_options) {
if (!output_options.dir) {
throw new Error("No 'dir' parameter provided in output options!");
}
const path = resolve(__dirname, output_options.dir, "manifest.json");
const contents = JSON.stringify(manifest);
await writeFile(path, contents);
},
},
],
build: {
lib: {
entry: {
[content_script_name]: resolve(
__dirname,
"src/content_scripts/main.ts",
),
[service_worker_name]: resolve(
__dirname,
"src/service_worker/main.ts",
),
},
formats: ["es"],
},
// inline sourcemaps during development for easier debugging
// (sourcemaps as sidecar files are not supported in Chromium browsers last I checked)
sourcemap: dev ? "inline" : false,
rollupOptions: {
output: {
entryFileNames: "[name].js",
chunkFileNames: "[name].js",
assetFileNames: "[name].[ext]",
banner: (chunk) => {
if (chunk.fileName.includes("node_modules")) {
// Don't add a banner to third-party code.
return "";
}
// Add a license header to the top of your scripts.
return license_banner;
},
},
},
target: `chrome${minimum_chrome_version}`,
minify: !dev,
cssMinify: !dev,
assetsInlineLimit: 0, // don't inline any assets, everything is already stored locally in the extension
},
esbuild: {
// drop any console.* methods when not building for development
drop: !dev ? ["console"] : [],
// drop any code labeled with "dev:" when not building for development
dropLabels: !dev ? ["dev"] : [],
},
};
});