63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
import vue from '@vitejs/plugin-vue';
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
import vueDevTools from 'vite-plugin-vue-devtools'
|
|
import federation from '@originjs/vite-plugin-federation';
|
|
import { fileURLToPath, URL } from "node:url";
|
|
import { nacosServiceManage } from "nacos-federation";
|
|
|
|
|
|
export default defineConfig(async () => {
|
|
const client = new nacosServiceManage({
|
|
serverList: '192.168.31.100:8848',
|
|
serviceName: 'app-product',
|
|
port: 1301
|
|
})
|
|
const sharedUrl = await client.find("app-shared")
|
|
|
|
return {
|
|
server: {
|
|
port: 1301,
|
|
host: '0.0.0.0',
|
|
strictPort: true,
|
|
cors: true
|
|
},
|
|
plugins: [
|
|
federation({
|
|
name: 'product',
|
|
remotes: {
|
|
shared: `${ sharedUrl }/assets/remoteEntry.js`
|
|
},
|
|
exposes: { // 暴露给主应用的资源(按功能分组)
|
|
'./ProductDomain': './src/domains/product/index.ts', // 领域层(实体、服务、接口等)
|
|
'./ProductRouter': './src/features/product/router/index.ts' // 商品路由
|
|
},
|
|
shared: {
|
|
vue: { import: false, generate: false, requiredVersion: '^3.5.18' },
|
|
'vue-router': { import: false, generate: false, requiredVersion: '^4.0.6' },
|
|
pinia: { import: false, generate: false, requiredVersion: '^3.0.3' },
|
|
}
|
|
}),
|
|
vue(),
|
|
vueJsx(),
|
|
vueDevTools()
|
|
],
|
|
build: {
|
|
target: 'esnext',
|
|
cssCodeSplit: true,
|
|
rollupOptions: {
|
|
output: {
|
|
minifyInternalExports: false
|
|
}
|
|
}
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src/', import.meta.url)),
|
|
'@shared': fileURLToPath(new URL('./src/shared/', import.meta.url)),
|
|
'@features': fileURLToPath(new URL('./src/features/', import.meta.url)),
|
|
'@domains': fileURLToPath(new URL('./src/domains/', import.meta.url))
|
|
},
|
|
},
|
|
}
|
|
}); |