Files
vue-ts-example/vite.config.ts
严浩 d3548f1105
All checks were successful
/ depcheck (push) Successful in 1m17s
/ build-and-deploy-to-vercel (push) Successful in 1m41s
/ surge (push) Successful in 6m16s
/ playwright (push) Successful in 2m39s
chore: update dev script to allow Vite to bind to all network interfaces
2025-02-11 18:36:10 +08:00

59 lines
1.9 KiB
TypeScript

// import { createSplitChunkOutput } from 'utils4u/rollup';
import { fileURLToPath, URL } from 'node:url';
import { createViteProxy } from 'utils4u/vite';
import { defineConfig, loadEnv } from 'vite';
import { Plugins } from './vite.config.plugins';
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
const isBuild = command === 'build';
const env = loadEnv(mode, process.cwd());
return {
base: env.VITE_BASE,
plugins: Plugins(),
define: {
$__DEV__: JSON.stringify(!isBuild),
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
proxy: createViteProxy(),
allowedHosts: ['.nwct.dev'],
},
build: {
minify: 'terser',
sourcemap: mode !== 'production' || env.VITE_SOURCE_MAP === 'true',
rollupOptions: {
onwarn: (warning, warn) => {
if (warning.code === 'EMPTY_BUNDLE') return;
if (warning.code === 'EVAL' && warning.id?.includes('node_modules/eruda')) return;
if (warning.code === 'EVAL' && warning.id?.includes('node_modules/mockjs')) return;
warn(warning);
},
// https://cn.rollupjs.org/configuration-options/#output-assetfilenames
// output: env.VITE_SPLIT_CHUNKS === 'true' ? (await import('utils4u/rollup')).createSplitChunkOutput() : undefined,
output: {
minifyInternalExports: false,
// manualChunks: {
// 'vendor/utils4u': ['utils4u', 'utils4u/vue-use', 'utils4u/primevue'],
// 'vendor/vue': ['vue'],
// 'vendor/primevue': ['primevue'],
// 'vendor/faker-js': ['@faker-js/faker'],
// 'vendor/mockjs': ['mockjs'],
// 'vendor/axios': ['axios', 'alova', '@alova/adapter-axios'],
// // 'vendor/nprogress': ['nprogress'],
// // 'vendor/formkit': ['@formkit/auto-animate'],
// },
},
},
},
};
});