mirror of
https://github.com/primedigitaltech/azon_seeker.git
synced 2026-01-19 13:13:22 +08:00
123 lines
3.1 KiB
TypeScript
123 lines
3.1 KiB
TypeScript
/// <reference types="vitest" />
|
|
|
|
import { dirname, relative } from 'node:path';
|
|
import type { UserConfig } from 'vite';
|
|
import { defineConfig } from 'vite';
|
|
import Vue from '@vitejs/plugin-vue';
|
|
import VueJsx from '@vitejs/plugin-vue-jsx';
|
|
import Icons from 'unplugin-icons/vite';
|
|
import IconsResolver from 'unplugin-icons/resolver';
|
|
import Components from 'unplugin-vue-components/vite';
|
|
import AutoImport from 'unplugin-auto-import/vite';
|
|
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
|
|
|
|
import { isDev, port, r } from './scripts/utils';
|
|
import packageJson from './package.json';
|
|
|
|
export const sharedConfig: UserConfig = {
|
|
root: r('src'),
|
|
resolve: {
|
|
alias: {
|
|
'~/': `${r('src')}/`,
|
|
},
|
|
},
|
|
define: {
|
|
__DEV__: isDev,
|
|
__NAME__: JSON.stringify(packageJson.name),
|
|
},
|
|
plugins: [
|
|
Vue(),
|
|
VueJsx(),
|
|
AutoImport({
|
|
imports: [
|
|
'vue',
|
|
{
|
|
dayjs: [['=', 'dayjs']],
|
|
},
|
|
{
|
|
'webextension-polyfill': [['=', 'browser']],
|
|
},
|
|
{
|
|
'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar', 'useModal'],
|
|
},
|
|
],
|
|
dts: r('src/auto-imports.d.ts'),
|
|
}),
|
|
|
|
// https://github.com/antfu/unplugin-vue-components
|
|
Components({
|
|
dirs: [r('src/components')],
|
|
// generate `components.d.ts` for ts support with Volar
|
|
dts: r('src/components.d.ts'),
|
|
resolvers: [
|
|
// auto import icons
|
|
IconsResolver({
|
|
prefix: '',
|
|
}),
|
|
// auto import naive ui
|
|
NaiveUiResolver(),
|
|
],
|
|
}),
|
|
|
|
// https://github.com/antfu/unplugin-icons
|
|
Icons(),
|
|
|
|
// rewrite assets to use relative path
|
|
{
|
|
name: 'assets-rewrite',
|
|
enforce: 'post',
|
|
apply: 'build',
|
|
transformIndexHtml(html, { path }) {
|
|
return html.replace(/"\/assets\//g, `"${relative(dirname(path), '/assets')}/`);
|
|
},
|
|
},
|
|
],
|
|
optimizeDeps: {
|
|
include: ['vue', '@vueuse/core', 'webextension-polyfill'],
|
|
exclude: ['vue-demi'],
|
|
},
|
|
};
|
|
|
|
export default defineConfig(({ command }) => ({
|
|
...sharedConfig,
|
|
base: command === 'serve' ? `http://localhost:${port}/` : '/dist/',
|
|
server: {
|
|
port,
|
|
hmr: {
|
|
host: 'localhost',
|
|
},
|
|
origin: `http://localhost:${port}`,
|
|
},
|
|
build: {
|
|
watch: isDev ? {} : undefined,
|
|
outDir: r('extension/dist'),
|
|
emptyOutDir: false,
|
|
sourcemap: isDev ? 'inline' : false,
|
|
// https://developer.chrome.com/docs/webstore/program_policies/#:~:text=Code%20Readability%20Requirements
|
|
terserOptions: {
|
|
mangle: false,
|
|
},
|
|
rollupOptions: {
|
|
input: {
|
|
sidepanel: r('src/sidepanel/index.html'),
|
|
options: r('src/options/index.html'),
|
|
},
|
|
output: {
|
|
manualChunks(id) {
|
|
if (id.includes('node_modules')) {
|
|
if (id.includes('exceljs')) return 'vendor-exceljs';
|
|
else if (id.includes('naive-ui')) return 'vendor-naive-ui';
|
|
else if (id.includes('vue')) return 'vendor-vue';
|
|
return 'vendor';
|
|
}
|
|
return null;
|
|
},
|
|
},
|
|
},
|
|
},
|
|
test: {
|
|
globals: true,
|
|
environment: 'jsdom',
|
|
},
|
|
}));
|