-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.chrome.ts
56 lines (51 loc) · 1.4 KB
/
vite.config.chrome.ts
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
import { defineConfig, Plugin } from 'vite';
import react from '@vitejs/plugin-react';
import { crx } from '@crxjs/vite-plugin';
import zipPack from 'vite-plugin-zip-pack';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import fs from 'node:fs';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import path from 'node:path';
import manifest from './manifest.json';
function myPlugin(): Plugin {
function updateManifest() {
const absolutePath = path.resolve('./dist-chrome/manifest.json');
const content = fs.readFileSync(absolutePath);
const test = JSON.parse(content);
test.web_accessible_resources = test.web_accessible_resources.map((i) => ({
...i,
use_dynamic_url: false,
}));
fs.writeFile(absolutePath, JSON.stringify(test, null, 2), (err) => {
if (err) {
console.error(err);
} else {
console.log('manifest.json updated');
}
});
}
return {
name: 'my-plugin',
generateBundle(options, bundle) {
console.log(bundle);
},
writeBundle() {
updateManifest();
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
build: {
outDir: 'dist-chrome',
emptyOutDir: true,
},
plugins: [
react(),
crx({ manifest: manifest as any }),
myPlugin(),
zipPack({ inDir: 'dist-chrome', outFileName: 'chrome.zip' }),
],
});