| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import { defineConfig, loadEnv } from 'vite';
- import path from 'path';
- import react from '@vitejs/plugin-react';
- export default defineConfig(({ mode, command }) => {
- const env = loadEnv(mode, path.join(process.cwd(), 'env'));
- return {
- envDir: './env',// 环境目录
- css: {
- preprocessorOptions: {
- less: {// 全局导入
- charset: false,
- additionalData: '@import "@/style/global.less";',
- }
- }
- },
- resolve: {
- // 别名
- alias: [
- {
- find: '@',
- replacement: path.resolve(__dirname, 'src'),
- }
- ],
- // 忽略文件后缀名
- extensions: ['.js', '.jsx', '.ts', '.tsx', '.less', '.json']
- },
- server: {
- // 监听所有地址
- host: '0.0.0.0',
- // 端口号
- port: 3100,
- // 自动打开浏览器
- open: true,
- // 热更新
- hmr: true,
- // 自动更换可用端口
- strictPort: false,
- // 代理规则
- proxy: {
- '/api/-captchaImage': {
- // 开启跨域
- changeOrigin: true,
- // 转发地址
- target: env.VITE_API_URL_img,
- // 路径重写
- rewrite: (path) => path.replace(/^\/api\/-captchaImage/i, '')
- },
- '/api': {
- // 开启跨域
- changeOrigin: true,
- // 转发地址
- target: env.VITE_API_URL,
- // 路径重写
- rewrite: (path) => path.replace(/^\/api/, ''),
- }
- }
- },
- build: {
- outDir: 'build',// 打包文件目录
- chunkSizeWarningLimit: 10240,// chunk大于10M触发警告
- // 底层配置
- rollupOptions: {
- output: {
- entryFileNames: 'js/[name]-[hash].js',
- chunkFileNames: 'js/[name]-[hash].js',
- }
- },
- },
- esbuild: {
- // drop: command === 'build' ? ['console', 'debugger'] : [],
- drop: command === 'build' ? [] : [],
- },
- plugins: [
- [react()],// React编译
- ],
- }
- })
|