123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { defineConfig } from 'vite';
- import { watchRebuildPlugin } from '@extension/hmr';
- import react from '@vitejs/plugin-react-swc';
- import deepmerge from 'deepmerge';
- import { isDev, isProduction } from './env.mjs';
- export const watchOption = isDev ? {
- buildDelay: 100,
- chokidar: {
- ignored:[
- /\/packages\/.*\.(ts|tsx|map)$/,
- ]
- }
- }: undefined;
- /**
- * @typedef {import('vite').UserConfig} UserConfig
- * @param {UserConfig} config
- * @returns {UserConfig}
- */
- export function withPageConfig(config) {
- return defineConfig(
- deepmerge(
- {
- base: '',
- plugins: [react(), isDev && watchRebuildPlugin({ refresh: true })],
- build: {
- sourcemap: isDev,
- minify: isProduction,
- reportCompressedSize: isProduction,
- emptyOutDir: isProduction,
- watch: watchOption,
- rollupOptions: {
- external: ['chrome'],
- },
- },
- define: {
- 'process.env.NODE_ENV': isDev ? `"development"` : `"production"`,
- },
- envDir: '../..'
- },
- config,
- ),
- );
- }
|