前端项目结构
This commit is contained in:
93
urbanLifelineWeb/packages/shared/vite.config.esm.ts
Normal file
93
urbanLifelineWeb/packages/shared/vite.config.esm.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import { resolve } from 'path'
|
||||
|
||||
/**
|
||||
* ES Module 构建配置
|
||||
* 用于 Import Maps 方案
|
||||
*
|
||||
* 策略:将 Vue、Element Plus 等依赖打包进共享模块
|
||||
* 业务应用只需引入 @shared/*,无需关心底层依赖
|
||||
*/
|
||||
export default defineConfig({
|
||||
plugins: [vue(), vueJsx()],
|
||||
|
||||
build: {
|
||||
lib: {
|
||||
entry: {
|
||||
components: resolve(__dirname, 'src/components/index.ts'),
|
||||
utils: resolve(__dirname, 'src/utils/index.ts'),
|
||||
api: resolve(__dirname, 'src/api/index.ts'),
|
||||
composables: resolve(__dirname, 'src/composables/index.ts'),
|
||||
types: resolve(__dirname, 'src/types/index.ts')
|
||||
},
|
||||
formats: ['es'], // 仅构建 ES Module
|
||||
fileName: (format, entryName) => `${entryName}.js`
|
||||
},
|
||||
|
||||
rollupOptions: {
|
||||
// ⚠️ 不外部化依赖,将它们打包进共享模块
|
||||
// 这样业务应用只需引入 @shared/* 即可
|
||||
external: [],
|
||||
|
||||
output: {
|
||||
// 保持 ES Module 格式
|
||||
format: 'es',
|
||||
// 导出命名导出
|
||||
exports: 'named',
|
||||
// 生成 sourcemap
|
||||
sourcemap: true,
|
||||
// 分块策略:将大的依赖分离出来
|
||||
manualChunks(id) {
|
||||
// Vue 核心
|
||||
if (id.includes('node_modules/vue/') ||
|
||||
id.includes('node_modules/@vue/')) {
|
||||
return 'vue-core'
|
||||
}
|
||||
// Vue Router
|
||||
if (id.includes('node_modules/vue-router/')) {
|
||||
return 'vue-router'
|
||||
}
|
||||
// Pinia
|
||||
if (id.includes('node_modules/pinia/')) {
|
||||
return 'pinia'
|
||||
}
|
||||
// Element Plus
|
||||
if (id.includes('node_modules/element-plus/')) {
|
||||
return 'element-plus'
|
||||
}
|
||||
// VueUse
|
||||
if (id.includes('node_modules/@vueuse/')) {
|
||||
return 'vueuse'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 输出目录
|
||||
outDir: 'dist/esm',
|
||||
emptyOutDir: true,
|
||||
|
||||
// 目标浏览器
|
||||
target: 'esnext',
|
||||
|
||||
// 不压缩(开发环境)
|
||||
minify: false,
|
||||
|
||||
// 启用代码分割
|
||||
cssCodeSplit: true
|
||||
},
|
||||
|
||||
// 开发服务器配置
|
||||
server: {
|
||||
port: 5000,
|
||||
host: true,
|
||||
cors: true,
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
||||
'Content-Type': 'application/javascript; charset=utf-8'
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user