| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import { defineConfig, loadEnv } from 'vite';
- import path from 'path';
- import vue from '@vitejs/plugin-vue';
- import { viteVConsole } from 'vite-plugin-vconsole';
- export default defineConfig(({ mode, command }) => {
- // 加载环境配置
- const env = loadEnv(mode, path.join(process.cwd(), 'env'));
- return {
- base: '/',// 基础路径
- envDir: './env',// 环境目录
- css: {
- preprocessorOptions: {
- scss: {// 全局导入
- charset: false,
- additionalData: '@import "./src/styles/variables";',
- },
- }
- },
- resolve: {
- // 别名
- alias: [
- {
- find: '/@',
- replacement: path.resolve(__dirname, './src'),
- }
- ],
- },
- server: {
- // 监听所有地址
- host: '0.0.0.0',
- // 自定义端口号
- port: 3010,
- // 自动打开浏览器
- open: true,
- // 开启热更新
- hmr: true,
- // 若端口被占用,自动尝试下一个可用端口
- strictPort: false,
- // 代理规则
- proxy: {
- '/api': {
- // 开启跨域
- changeOrigin: true,
- // 转发地址
- target: env.VITE_API_URL,
- // 路径重写
- rewrite: (path) => path.replace(/^\/api/, ''),
- }
- }
- },
- build: {
- chunkSizeWarningLimit: 10240,// 触发警告的chunk大小10M
- // 底层配置
- rollupOptions: {
- output: {
- entryFileNames: 'js/[name]-[hash].js',
- chunkFileNames: 'js/[name]-[hash].js',
- }
- },
- },
- esbuild: {
- drop: command === 'build' ? ['console', 'debugger'] : [],
- },
- plugins: [
- vue(),
- viteVConsole({
- entry: path.resolve(__dirname, './src/main.ts'),// 入口文件
- localEnabled: command === 'serve',// serve开发环境下
- enabled: command === 'serve',// 本地运行时开启
- config: {// 配置
- maxLogNumber: 1000,
- theme: 'light'
- }
- }),
- ],
- }
- })
|