123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { fileURLToPath, URL } from 'node:url'
- import { defineConfig, loadEnv } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import vueDevTools from 'vite-plugin-vue-devtools'
- import Components from 'unplugin-vue-components/vite'
- import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
- import { readFileSync } from 'fs'
- import { formatDateTime } from './src/utils'
- import buildInfoPlugin from './scripts/build-info-plugin'
- import path from 'path'
- // https://vite.dev/config/
- export default defineConfig(({ mode }) => {
- // 加载环境变量
- const env = loadEnv(mode, process.cwd(), '')
- // 获取当前环境的API主机
- const apiHost = env.VITE_APP_HOST
- const mqttHostAlarm = env.VITE_MQTT_HOST_ALARM
- const mqttHostPoint = env.VITE_MQTT_HOST_POINT
- // 添加日志输出
- console.log('📘📘📘 Environment LOG 📘📘📘', {
- mode,
- apiHost,
- mqttHostAlarm,
- mqttHostPoint,
- })
- const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'))
- return {
- plugins: [
- vue(),
- vueDevTools(),
- buildInfoPlugin(mode),
- Components({
- resolvers: [
- AntDesignVueResolver({
- importStyle: false, // css in js
- }),
- ],
- }),
- ],
- define: {
- __APP_VERSION__: JSON.stringify(pkg.version),
- __BUILD_TIME__: JSON.stringify(formatDateTime(new Date())),
- },
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url)),
- 'three/addons': path.join(__dirname, 'node_modules/three/addons'),
- },
- },
- server: {
- proxy: {
- '/portal-service-server': {
- target: apiHost,
- changeOrigin: true,
- secure: false,
- rewrite: (path) => path,
- },
- '/pub': {
- target: apiHost,
- changeOrigin: true,
- secure: false,
- rewrite: (path) => path,
- },
- },
- cors: true,
- },
- build: {
- chunkSizeWarningLimit: 1000,
- rollupOptions: {
- output: {
- manualChunks(id) {
- if (id.includes('node_modules')) {
- if (id.includes('three')) return 'threejs'
- if (id.includes('echarts')) return 'echarts'
- if (id.includes('ant-design-vue')) return 'antdv'
- if (id.includes('tiny-pinyin')) return 'pinyin'
- if (id.includes('lodash-es')) return 'lodash'
- if (id.includes('vue')) return 'vue'
- return 'vendor'
- }
- },
- },
- },
- },
- }
- })
|