| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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: {// scss配置全局导入
- 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: {
- outDir: 'dist',// 指定打包文件根目录
- sourcemap: false,// 构建后不生成源代码
- write: true,// 构建的文件写入磁盘
- 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'
- }
- }),
- ],
- }
- })
|