import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vueJsx from '@vitejs/plugin-vue-jsx' import { federation } from '@module-federation/vite' import { resolve, dirname } from 'path' import { fileURLToPath } from 'url' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) export default defineConfig({ // Platform 应用的基础路径 base: '/platform/', plugins: [ vue({ script: { defineModel: true, propsDestructure: true } }), vueJsx(), federation({ name: 'platform', remotes: { shared: { type: 'module', name: 'shared', entry: 'http://localhost:7000/remoteEntry.js' } }, shared: { vue: {}, 'vue-router': {}, 'element-plus': {}, axios: {} } }) ], define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: true, __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true }, resolve: { alias: { '@': resolve(__dirname, 'src') } }, server: { port: 7001, host: true, cors: true, open: '/', // 开发时自动打开到根路径 proxy: { '/api': { target: 'http://localhost:8180', changeOrigin: true, rewrite: (path: string) => path.replace(/^\/api/, '') } } }, build: { outDir: 'dist', sourcemap: true, rollupOptions: { output: { manualChunks: { 'vue-vendor': ['vue', 'vue-router', 'pinia'], 'element-plus': ['element-plus'] } } } } })