forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.configs.ts
117 lines (111 loc) · 2.61 KB
/
vite.configs.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
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
import type { UserConfig } from 'vite';
import * as manifests from './manifest.config';
import solid from 'vite-plugin-solid';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import compileConnectors from './scripts/compile-connectors';
import makeManifest from './scripts/make-manifest';
import { isDev, releaseTarget, resolvePath } from 'scripts/util';
import minifyImages from 'scripts/minify-images';
import generateIcons from 'scripts/generate-icons';
import ConditionalCompile from 'vite-plugin-conditional-compiler';
const dist = resolvePath('build');
const root = resolvePath('src');
const builds = {
chrome: resolvePath(dist, 'chrome'),
firefox: resolvePath(dist, 'firefox'),
safari: resolvePath(dist, 'safariraw'),
error: resolvePath(dist, 'error'),
};
const common: UserConfig = {
resolve: {
alias: [
{ find: '@', replacement: '/src' },
{ find: '#', replacement: '/tests' },
],
},
};
function distRoot() {
const browser = releaseTarget;
if (!browser || !(browser in builds)) {
return builds.error;
}
return builds[browser as keyof typeof builds];
}
export const buildBackground: UserConfig = {
...common,
build: {
minify: !isDev(),
outDir: resolvePath(distRoot(), 'background'),
emptyOutDir: true,
watch: isDev() ? {} : null,
lib: {
entry: resolvePath(root, 'core', 'background', 'main.ts'),
name: manifests.common.name,
formats: ['iife'],
},
rollupOptions: {
output: {
entryFileNames: 'main.js',
extend: true,
},
},
},
plugins: [ConditionalCompile()],
};
export const buildContent: UserConfig = {
...common,
build: {
minify: !isDev(),
outDir: resolvePath(distRoot(), 'content'),
emptyOutDir: true,
watch: isDev() ? {} : null,
lib: {
entry: resolvePath(root, 'core', 'content', 'main.ts'),
name: manifests.common.name,
formats: ['iife'],
},
rollupOptions: {
output: {
entryFileNames: 'main.js',
extend: true,
},
},
},
plugins: [ConditionalCompile()],
};
export const buildStart: UserConfig = {
...common,
build: {
minify: !isDev(),
outDir: distRoot(),
emptyOutDir: false,
watch: isDev() ? {} : null,
sourcemap: isDev(),
rollupOptions: {
input: {
popup: resolvePath(root, 'ui', 'popup', 'index.html'),
options: resolvePath(root, 'ui', 'options', 'index.html'),
},
output: {},
},
},
plugins: [
ConditionalCompile(),
solid(),
makeManifest(),
generateIcons(),
viteStaticCopy({
targets: [
{
src: resolvePath(root, '_locales'),
dest: '',
},
],
}),
compileConnectors({
isDev: isDev(),
watchDirectory: 'src/connectors/*',
}),
minifyImages({ isDev: isDev() }),
],
};