前端项目结构

This commit is contained in:
2025-12-02 15:55:30 +08:00
parent 2a9e624ba9
commit 28787e5b29
18 changed files with 2545 additions and 2167 deletions

View File

@@ -0,0 +1,22 @@
FROM node:20-alpine
# 安装 pnpm
RUN npm install -g pnpm@latest
WORKDIR /app
# 复制 package.json
COPY packages/shared/package.json ./
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
# 安装依赖
RUN pnpm install --frozen-lockfile
# 复制源代码
COPY packages/shared/ ./
# 暴露端口
EXPOSE 5000
# 开发模式启动(支持热更新)
CMD ["pnpm", "dev", "--host", "0.0.0.0"]

View File

@@ -0,0 +1,28 @@
{
"name": "@shared/all",
"version": "1.0.0",
"type": "module",
"private": true,
"scripts": {
"dev": "vite --port 5000 --host",
"build": "run-p build:*",
"build:esm": "vite build --mode esm",
"build:federation": "vite build --mode federation",
"preview": "vite preview --port 5000"
},
"dependencies": {
"vue": "^3.5.13",
"vue-router": "^4.5.0",
"pinia": "^2.2.8",
"element-plus": "^2.9.1",
"@vueuse/core": "^11.3.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.1",
"@vitejs/plugin-vue-jsx": "^4.1.1",
"typescript": "^5.7.2",
"vite": "^6.0.3",
"@originjs/vite-plugin-federation": "^1.3.6",
"npm-run-all": "^4.1.5"
}
}

View 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'
}
}
})