forked from listen1/listen1_chrome_extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
69 lines (65 loc) · 2.21 KB
/
vite.config.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
import { resolve } from 'path';
import vueI18n from '@intlify/vite-plugin-vue-i18n';
import vue from '@vitejs/plugin-vue';
import { chromeExtension, simpleReloader } from 'rollup-plugin-chrome-extension';
import zip from 'vite-plugin-zip';
import { defineConfig, build } from 'vite';
const { NODE_ENV, BUILD_ELECTRON, TAURI_PLATFORM } = process.env;
const production = NODE_ENV === 'production';
if (process.argv.includes('-w') || process.argv.includes('--watch')) process.env.ROLLUP_WATCH = 'true';
const provider_src = resolve(__dirname, `src/${TAURI_PLATFORM ? 'backend_provider' : 'provider'}`);
const chromeExtPlugin = chromeExtension();
// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
'vue-i18n': 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js',
'node-forge': 'node-forge/dist/forge.min.js',
'@provider': provider_src,
}
},
base: '',
root: 'src/',
define: {
__VUE_I18N_FULL_INSTALL__: 'false',
__VUE_I18N_LEGACY_API__: 'false',
__VUE_I18N_PROD_DEVTOOLS__: 'false',
__INTLIFY_PROD_DEVTOOLS__: 'false',
__VUE_OPTIONS_API__: 'false',
__VUE_PROD_DEVTOOLS__: 'false'
},
plugins: [
{
name: 'inject-css',
buildStart() {
const $ = chromeExtPlugin._plugins.html.cache.html$[0];
if ($('head link').last().attr('href') !== 'assets/main.css') {
$('head').last().append($('<link rel="stylesheet" href="assets/main.css">'));
}
}
},
// @ts-ignore: Type Mismatch Error
chromeExtPlugin,
vueI18n({ include: 'src/i18n/*.json', runtimeOnly: true }),
vue({ reactivityTransform: true }),
// @ts-ignore: Type Mismatch Error
simpleReloader(),
production && zip({ dir: 'artifacts' })
],
build: {
//we are still in develop here, since sourcemap won't work in extension, it's better not minify the files
minify: false,
emptyOutDir: true,
rollupOptions: {
external: ['./assets/main.css'],
input: ['./src/manifest.ts'],
output: {
dir: BUILD_ELECTRON ? 'electron_src/dist' : 'dist',
format: 'esm',
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `assets/[name].[ext]`
}
}
}
});