优化全局样式和 element ui框架,修改nacos-federation,增加打包依赖分析等
This commit is contained in:
@@ -20,13 +20,16 @@
|
||||
"vue-router": "^4.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"@originjs/vite-plugin-federation": "^1.4.1",
|
||||
"@tsconfig/node22": "^22.0.2",
|
||||
"@types/node": "^22.18.6",
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
"@vitejs/plugin-vue-jsx": "^5.1.1",
|
||||
"@vue/tsconfig": "^0.7.0",
|
||||
"element-plus": "^2.11.3",
|
||||
"npm-run-all2": "^8.0.4",
|
||||
"rollup-plugin-visualizer": "^6.0.3",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.1.6",
|
||||
"vite-plugin-vue-devtools": "^8.0.2",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
.ProductDetail {
|
||||
.title {
|
||||
color: blue;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import styles from './ProductDetail.module.less'
|
||||
|
||||
import { product } from '@domains/product/di/productModule';
|
||||
import { ProductType } from '@domains/product/domain/type/ProductType';
|
||||
import { defineComponent, onMounted, reactive } from 'vue'
|
||||
@@ -34,8 +36,8 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
return () => (
|
||||
<div class="ProductDetail">
|
||||
<h1>商品领域模块 - 商品详情页面</h1>
|
||||
<div class={ styles.ProductDetail }>
|
||||
<h1 class={ styles.title }>商品领域模块 - 商品详情页面</h1>
|
||||
<hr/>
|
||||
<p>商品id:{ state.id }</p>
|
||||
{ state.item.name }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.ProductList {
|
||||
.test {
|
||||
color: red;
|
||||
color: var(--theme-color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { defineComponent, onMounted, reactive } from 'vue'
|
||||
import { useRouter } from 'vue-router';
|
||||
import { product } from '@domains/product/di/productModule';
|
||||
import { ProductType } from '@domains/product/domain/type/ProductType';
|
||||
import { ElCard, ElIcon, Icons } from "shared/element-plus";
|
||||
|
||||
interface storeType {
|
||||
list: Array<ProductType>
|
||||
@@ -29,25 +30,41 @@ export default defineComponent({
|
||||
console.log("state.list: ", state.list);
|
||||
}
|
||||
|
||||
const ElCardHeader = () => {
|
||||
return (
|
||||
<div class="card-header">
|
||||
<ElIcon size={ 15 }>
|
||||
<Icons.Position></Icons.Position>
|
||||
</ElIcon>
|
||||
<span>Card 头部</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const ElCardFooter = () => {
|
||||
return <div>Footer 底部</div>
|
||||
}
|
||||
|
||||
return () => (
|
||||
<div class={ styles.ProductList }>
|
||||
<h1 class={ styles.test }>商品领域模块 - 商品列表页面3</h1>
|
||||
<hr/>
|
||||
<h2>从Deno 后端 加载的数据,点击进详情</h2>
|
||||
<ul>
|
||||
{
|
||||
state.list.map(item =>
|
||||
<li key={ item.id } onClick={ () => {
|
||||
router.push({
|
||||
name: 'ProductDetail',
|
||||
query: { id: item.id }
|
||||
});
|
||||
} }>
|
||||
{ item.id } | { item.name } | ¥{ item.price }
|
||||
</li>
|
||||
)
|
||||
}
|
||||
</ul>
|
||||
<ElCard>
|
||||
{ {
|
||||
header: () => ElCardHeader(),
|
||||
footer: () => ElCardFooter(),
|
||||
default: () =>
|
||||
state.list.map(item =>
|
||||
<p key={ item.id } onClick={ () => {
|
||||
router.push({ name: 'ProductDetail', query: { id: item.id } });
|
||||
} }>
|
||||
{ item.id } | { item.name } | ¥{ item.price }
|
||||
</p>
|
||||
)
|
||||
} }
|
||||
</ElCard>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
declare module 'shared/infra' {
|
||||
export const http: any;
|
||||
}
|
||||
29
front-end/app-product/src/shared/types/shared.d.ts
vendored
Normal file
29
front-end/app-product/src/shared/types/shared.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module 'shared/infra' {
|
||||
export const http: any;
|
||||
}
|
||||
|
||||
declare module 'shared/utils' {
|
||||
export const UrlCheckUtils: any;
|
||||
}
|
||||
|
||||
declare module 'shared/element-plus' {
|
||||
import * as ElementPlus from 'element-plus';
|
||||
import * as ElementPlusIcons from '@element-plus/icons-vue';
|
||||
import type { App } from 'vue';
|
||||
export * from 'element-plus';
|
||||
export import Icons = ElementPlusIcons;
|
||||
|
||||
export function init(app: App): void;
|
||||
|
||||
const defaultExport: typeof ElementPlus & {
|
||||
Icons: typeof ElementPlusIcons;
|
||||
init: typeof init;
|
||||
};
|
||||
export default defaultExport;
|
||||
}
|
||||
|
||||
declare module 'shared/normalize' {
|
||||
export const init: () => void;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
import federation from '@originjs/vite-plugin-federation';
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
import { nacosRegVitePlugin } from "nacos-federation";
|
||||
import { visualizer } from 'rollup-plugin-visualizer';
|
||||
|
||||
export default defineConfig(async ({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
@@ -35,7 +36,14 @@ export default defineConfig(async ({ mode }) => {
|
||||
}),
|
||||
vue(),
|
||||
vueJsx(),
|
||||
vueDevTools()
|
||||
vueDevTools(),
|
||||
visualizer({
|
||||
title: "商品模块依赖分析",
|
||||
filename: 'dist/stats.html', // 分析文件输出路径
|
||||
open: false, // 构建完成后自动打开
|
||||
gzipSize: true, // 显示gzip后的大小
|
||||
brotliSize: true, // 显示brotli后的大小
|
||||
})
|
||||
],
|
||||
build: {
|
||||
target: 'esnext',
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
"rollup-plugin-visualizer": "^6.0.3",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.1.6"
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class AxiosInfra {
|
||||
public constructor() {
|
||||
this.instance = axios.create({
|
||||
baseURL: UrlCheckUtils.check(),
|
||||
timeout: 10000,
|
||||
timeout: Number(import.meta.env.VITE_HTTPTIMEOUT),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
@@ -1,34 +1,22 @@
|
||||
// app-shared/src/lib/element-plus.ts
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css';
|
||||
import * as ElementPlusIcons from '@element-plus/icons-vue';
|
||||
|
||||
import { App } from 'vue';
|
||||
|
||||
// 导出安装函数
|
||||
export const initElement = (app: App) => {
|
||||
console.log("[app-shared] element-plus UI框架 已加载...")
|
||||
|
||||
export * from 'element-plus';
|
||||
export * as Icons from '@element-plus/icons-vue';
|
||||
|
||||
// 保留你的 init 函数
|
||||
export const init = (app: App) => {
|
||||
app.use(ElementPlus);
|
||||
};
|
||||
|
||||
// 导出 element-plus 的主要组件
|
||||
export {
|
||||
ElButton,
|
||||
ElInput,
|
||||
ElTable,
|
||||
ElForm,
|
||||
ElMessage,
|
||||
} from 'element-plus';
|
||||
|
||||
|
||||
export {
|
||||
Filter as FilterIcon,
|
||||
Message as MessageIcon,
|
||||
Sort as SortIcon,
|
||||
Search as SearchIcon,
|
||||
} from '@element-plus/icons-vue';
|
||||
|
||||
// 导出整个图标
|
||||
export const Icons = ElementPlusIcons;
|
||||
|
||||
// 导出整个ui框架
|
||||
export default ElementPlus;
|
||||
// 如果你仍然需要一个默认导出,可以这样做
|
||||
const sharedUI = {
|
||||
...ElementPlus, // 合并 ElementPlus 的所有导出
|
||||
Icons: ElementPlusIcons,
|
||||
init
|
||||
};
|
||||
export default sharedUI;
|
||||
@@ -1,5 +1,5 @@
|
||||
import "./normalize.less";
|
||||
|
||||
export const init = () => {
|
||||
export const initNormalizeStyles = () => {
|
||||
console.log("[app-shared] 清除默认样式normalize.less 已加载...")
|
||||
}
|
||||
@@ -2,11 +2,18 @@
|
||||
* Copyright (c) 2020. bmy
|
||||
*/
|
||||
|
||||
html, body, #app {
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body, h1, h2, h3, h4, h5, h6, p, a {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: sans-serif; /* 1 */
|
||||
line-height: 1.15; /* 2 */
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import "./variables.less";
|
||||
import "./mixins.less";
|
||||
// import "./mixins.less";
|
||||
|
||||
export const lessPub = '';
|
||||
export const initPubStyles = () => {
|
||||
console.log("[app-shared] variables.less 和 mixins.less 已加载...")
|
||||
}
|
||||
@@ -3,311 +3,7 @@
|
||||
*/
|
||||
|
||||
// 公共css样式,可以在 页面组件中直接使用变量名称
|
||||
// 具体看 components/home.styl
|
||||
@theme-color: red;
|
||||
@test-color: yellow;
|
||||
|
||||
@red50: #ffebee;
|
||||
@red100: #ffcdd2;
|
||||
@red200: #ef9a9a;
|
||||
@red300: #e57373;
|
||||
@red400: #ef5350;
|
||||
@red500: #f44336;
|
||||
@red600: #e53935;
|
||||
@red700: #d32f2f;
|
||||
@red800: #c62828;
|
||||
@red900: #b71c1c;
|
||||
@redA100: #ff8a80;
|
||||
@redA200: #ff5252;
|
||||
@redA400: #ff1744;
|
||||
@redA700: #d50000;
|
||||
@red: @red500;
|
||||
|
||||
@pink50: #fce4ec;
|
||||
@pink100: #f8bbd0;
|
||||
@pink200: #f48fb1;
|
||||
@pink300: #f06292;
|
||||
@pink400: #ec407a;
|
||||
@pink500: #e91e63;
|
||||
@pink600: #d81b60;
|
||||
@pink700: #c2185b;
|
||||
@pink800: #ad1457;
|
||||
@pink900: #880e4f;
|
||||
@pinkA100: #ff80ab;
|
||||
@pinkA200: #ff4081;
|
||||
@pinkA400: #f50057;
|
||||
@pinkA700: #c51162;
|
||||
@pink: @pink500;
|
||||
|
||||
@purple50: #f3e5f5;
|
||||
@purple100: #e1bee7;
|
||||
@purple200: #ce93d8;
|
||||
@purple300: #ba68c8;
|
||||
@purple400: #ab47bc;
|
||||
@purple500: #9c27b0;
|
||||
@purple600: #8e24aa;
|
||||
@purple700: #7b1fa2;
|
||||
@purple800: #6a1b9a;
|
||||
@purple900: #4a148c;
|
||||
@purpleA100: #ea80fc;
|
||||
@purpleA200: #e040fb;
|
||||
@purpleA400: #d500f9;
|
||||
@purpleA700: #aa00ff;
|
||||
@purple: @purple500;
|
||||
|
||||
@deepPurple50: #ede7f6;
|
||||
@deepPurple100: #d1c4e9;
|
||||
@deepPurple200: #b39ddb;
|
||||
@deepPurple300: #9575cd;
|
||||
@deepPurple400: #7e57c2;
|
||||
@deepPurple500: #673ab7;
|
||||
@deepPurple600: #5e35b1;
|
||||
@deepPurple700: #512da8;
|
||||
@deepPurple800: #4527a0;
|
||||
@deepPurple900: #311b92;
|
||||
@deepPurpleA100: #b388ff;
|
||||
@deepPurpleA200: #7c4dff;
|
||||
@deepPurpleA400: #651fff;
|
||||
@deepPurpleA700: #6200ea;
|
||||
@deepPurple: @deepPurple500;
|
||||
|
||||
@indigo50: #e8eaf6;
|
||||
@indigo100: #c5cae9;
|
||||
@indigo200: #9fa8da;
|
||||
@indigo300: #7986cb;
|
||||
@indigo400: #5c6bc0;
|
||||
@indigo500: #3f51b5;
|
||||
@indigo600: #3949ab;
|
||||
@indigo700: #303f9f;
|
||||
@indigo800: #283593;
|
||||
@indigo900: #1a237e;
|
||||
@indigoA100: #8c9eff;
|
||||
@indigoA200: #536dfe;
|
||||
@indigoA400: #3d5afe;
|
||||
@indigoA700: #304ffe;
|
||||
@indigo: @indigo500;
|
||||
|
||||
@blue50: #e3f2fd;
|
||||
@blue100: #bbdefb;
|
||||
@blue200: #90caf9;
|
||||
@blue300: #64b5f6;
|
||||
@blue400: #42a5f5;
|
||||
@blue500: #2196f3;
|
||||
@blue600: #1e88e5;
|
||||
@blue700: #1976d2;
|
||||
@blue800: #1565c0;
|
||||
@blue900: #0d47a1;
|
||||
@blueA100: #82b1ff;
|
||||
@blueA200: #448aff;
|
||||
@blueA400: #2979ff;
|
||||
@blueA700: #2962ff;
|
||||
@blue: @blue500;
|
||||
|
||||
@lightBlue50: #e1f5fe;
|
||||
@lightBlue100: #b3e5fc;
|
||||
@lightBlue200: #81d4fa;
|
||||
@lightBlue300: #4fc3f7;
|
||||
@lightBlue400: #29b6f6;
|
||||
@lightBlue500: #03a9f4;
|
||||
@lightBlue600: #039be5;
|
||||
@lightBlue700: #0288d1;
|
||||
@lightBlue800: #0277bd;
|
||||
@lightBlue900: #01579b;
|
||||
@lightBlueA100: #80d8ff;
|
||||
@lightBlueA200: #40c4ff;
|
||||
@lightBlueA400: #00b0ff;
|
||||
@lightBlueA700: #0091ea;
|
||||
@lightBlue: @lightBlue500;
|
||||
|
||||
@cyan50: #e0f7fa;
|
||||
@cyan100: #b2ebf2;
|
||||
@cyan200: #80deea;
|
||||
@cyan300: #4dd0e1;
|
||||
@cyan400: #26c6da;
|
||||
@cyan500: #00bcd4;
|
||||
@cyan600: #00acc1;
|
||||
@cyan700: #0097a7;
|
||||
@cyan800: #00838f;
|
||||
@cyan900: #006064;
|
||||
@cyanA100: #84ffff;
|
||||
@cyanA200: #18ffff;
|
||||
@cyanA400: #00e5ff;
|
||||
@cyanA700: #00b8d4;
|
||||
@cyan: @cyan500;
|
||||
|
||||
@teal50: #e0f2f1;
|
||||
@teal100: #b2dfdb;
|
||||
@teal200: #80cbc4;
|
||||
@teal300: #4db6ac;
|
||||
@teal400: #26a69a;
|
||||
@teal500: #009688;
|
||||
@teal600: #00897b;
|
||||
@teal700: #00796b;
|
||||
@teal800: #00695c;
|
||||
@teal900: #004d40;
|
||||
@tealA100: #a7ffeb;
|
||||
@tealA200: #64ffda;
|
||||
@tealA400: #1de9b6;
|
||||
@tealA700: #00bfa5;
|
||||
@teal: @teal500;
|
||||
|
||||
@green50: #e8f5e9;
|
||||
@green100: #c8e6c9;
|
||||
@green200: #a5d6a7;
|
||||
@green300: #81c784;
|
||||
@green400: #66bb6a;
|
||||
@green500: #4caf50;
|
||||
@green600: #43a047;
|
||||
@green700: #388e3c;
|
||||
@green800: #2e7d32;
|
||||
@green900: #1b5e20;
|
||||
@greenA100: #b9f6ca;
|
||||
@greenA200: #69f0ae;
|
||||
@greenA400: #00e676;
|
||||
@greenA700: #00c853;
|
||||
@green: @green500;
|
||||
|
||||
@lightGreen50: #f1f8e9;
|
||||
@lightGreen100: #dcedc8;
|
||||
@lightGreen200: #c5e1a5;
|
||||
@lightGreen300: #aed581;
|
||||
@lightGreen400: #9ccc65;
|
||||
@lightGreen500: #8bc34a;
|
||||
@lightGreen600: #7cb342;
|
||||
@lightGreen700: #689f38;
|
||||
@lightGreen800: #558b2f;
|
||||
@lightGreen900: #33691e;
|
||||
@lightGreenA100: #ccff90;
|
||||
@lightGreenA200: #b2ff59;
|
||||
@lightGreenA400: #76ff03;
|
||||
@lightGreenA700: #64dd17;
|
||||
@lightGreen: @lightGreen500;
|
||||
|
||||
@lime50: #f9fbe7;
|
||||
@lime100: #f0f4c3;
|
||||
@lime200: #e6ee9c;
|
||||
@lime300: #dce775;
|
||||
@lime400: #d4e157;
|
||||
@lime500: #cddc39;
|
||||
@lime600: #c0ca33;
|
||||
@lime700: #afb42b;
|
||||
@lime800: #9e9d24;
|
||||
@lime900: #827717;
|
||||
@limeA100: #f4ff81;
|
||||
@limeA200: #eeff41;
|
||||
@limeA400: #c6ff00;
|
||||
@limeA700: #aeea00;
|
||||
@lime: @lime500;
|
||||
|
||||
@yellow50: #fffde7;
|
||||
@yellow100: #fff9c4;
|
||||
@yellow200: #fff59d;
|
||||
@yellow300: #fff176;
|
||||
@yellow400: #ffee58;
|
||||
@yellow500: #ffeb3b;
|
||||
@yellow600: #fdd835;
|
||||
@yellow700: #fbc02d;
|
||||
@yellow800: #f9a825;
|
||||
@yellow900: #f57f17;
|
||||
@yellowA100: #ffff8d;
|
||||
@yellowA200: #ffff00;
|
||||
@yellowA400: #ffea00;
|
||||
@yellowA700: #ffd600;
|
||||
@yellow: @yellow500;
|
||||
|
||||
@amber50: #fff8e1;
|
||||
@amber100: #ffecb3;
|
||||
@amber200: #ffe082;
|
||||
@amber300: #ffd54f;
|
||||
@amber400: #ffca28;
|
||||
@amber500: #ffc107;
|
||||
@amber600: #ffb300;
|
||||
@amber700: #ffa000;
|
||||
@amber800: #ff8f00;
|
||||
@amber900: #ff6f00;
|
||||
@amberA100: #ffe57f;
|
||||
@amberA200: #ffd740;
|
||||
@amberA400: #ffc400;
|
||||
@amberA700: #ffab00;
|
||||
@amber: @amber500;
|
||||
|
||||
@orange50: #fff3e0;
|
||||
@orange100: #ffe0b2;
|
||||
@orange200: #ffcc80;
|
||||
@orange300: #ffb74d;
|
||||
@orange400: #ffa726;
|
||||
@orange500: #ff9800;
|
||||
@orange600: #fb8c00;
|
||||
@orange700: #f57c00;
|
||||
@orange800: #ef6c00;
|
||||
@orange900: #e65100;
|
||||
@orangeA100: #ffd180;
|
||||
@orangeA200: #ffab40;
|
||||
@orangeA400: #ff9100;
|
||||
@orangeA700: #ff6d00;
|
||||
@orange: @orange500;
|
||||
|
||||
@deepOrange50: #fbe9e7;
|
||||
@deepOrange100: #ffccbc;
|
||||
@deepOrange200: #ffab91;
|
||||
@deepOrange300: #ff8a65;
|
||||
@deepOrange400: #ff7043;
|
||||
@deepOrange500: #ff5722;
|
||||
@deepOrange600: #f4511e;
|
||||
@deepOrange700: #e64a19;
|
||||
@deepOrange800: #d84315;
|
||||
@deepOrange900: #bf360c;
|
||||
@deepOrangeA100: #ff9e80;
|
||||
@deepOrangeA200: #ff6e40;
|
||||
@deepOrangeA400: #ff3d00;
|
||||
@deepOrangeA700: #dd2c00;
|
||||
@deepOrange: @deepOrange500;
|
||||
|
||||
@brown50: #efebe9;
|
||||
@brown100: #d7ccc8;
|
||||
@brown200: #bcaaa4;
|
||||
@brown300: #a1887f;
|
||||
@brown400: #8d6e63;
|
||||
@brown500: #795548;
|
||||
@brown600: #6d4c41;
|
||||
@brown700: #5d4037;
|
||||
@brown800: #4e342e;
|
||||
@brown900: #3e2723;
|
||||
@brown: @brown500;
|
||||
|
||||
@blueGrey50: #eceff1;
|
||||
@blueGrey100: #cfd8dc;
|
||||
@blueGrey200: #b0bec5;
|
||||
@blueGrey300: #90a4ae;
|
||||
@blueGrey400: #78909c;
|
||||
@blueGrey500: #607d8b;
|
||||
@blueGrey600: #546e7a;
|
||||
@blueGrey700: #455a64;
|
||||
@blueGrey800: #37474f;
|
||||
@blueGrey900: #263238;
|
||||
@blueGrey: @blueGrey500;
|
||||
|
||||
@grey50: #fafafa;
|
||||
@grey100: #f5f5f5;
|
||||
@grey200: #eeeeee;
|
||||
@grey300: #e0e0e0;
|
||||
@grey400: #bdbdbd;
|
||||
@grey500: #9e9e9e;
|
||||
@grey600: #757575;
|
||||
@grey700: #616161;
|
||||
@grey800: #424242;
|
||||
@grey900: #212121;
|
||||
@grey: @grey500;
|
||||
|
||||
@black: #000000;
|
||||
@white: #ffffff;
|
||||
|
||||
@transparent: rgba(0, 0, 0, 0);
|
||||
@fullBlack: rgba(0, 0, 0, 1);
|
||||
@darkBlack: rgba(0, 0, 0, 0.87);
|
||||
@lightBlack: rgba(0, 0, 0, 0.54);
|
||||
@minBlack: rgba(0, 0, 0, 0.26);
|
||||
@faintBlack: rgba(0, 0, 0, 0.12);
|
||||
@fullWhite: rgba(255, 255, 255, 1);
|
||||
@darkWhite: rgba(255, 255, 255, 0.87);
|
||||
@lightWhite: rgba(255, 255, 255, 0.54);
|
||||
:root {
|
||||
--theme-color: red;
|
||||
--test-color: yellow;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import federation from "@originjs/vite-plugin-federation";
|
||||
import { nacosRegVitePlugin } from "nacos-federation";
|
||||
// @ts-ignore
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import visualizer from 'rollup-plugin-visualizer';
|
||||
|
||||
export default defineConfig(async ({ mode }): Promise<UserConfig> => {
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
@@ -24,6 +25,7 @@ export default defineConfig(async ({ mode }): Promise<UserConfig> => {
|
||||
"./utils": "./src/utils/index.ts",
|
||||
"./element-plus": "./src/lib/element-plus.ts",
|
||||
"./normalize": "./src/styles/common/index.ts",
|
||||
"./pub": "./src/styles/pub/index.ts",
|
||||
},
|
||||
shared: {
|
||||
vue: { import: false, generate: false, requiredVersion: '^3.5.18' },
|
||||
@@ -31,7 +33,14 @@ export default defineConfig(async ({ mode }): Promise<UserConfig> => {
|
||||
'element-plus': { requiredVersion: '^2.11.3' }
|
||||
}
|
||||
}),
|
||||
vue()
|
||||
vue(),
|
||||
visualizer({
|
||||
title: "共享模块依赖分析",
|
||||
filename: 'dist/stats.html', // 分析文件输出路径
|
||||
open: false, // 构建完成后自动打开
|
||||
gzipSize: true, // 显示gzip后的大小
|
||||
brotliSize: true, // 显示brotli后的大小
|
||||
})
|
||||
],
|
||||
build: {
|
||||
target: 'esnext',
|
||||
|
||||
@@ -18,9 +18,12 @@
|
||||
"vue-router": "^4.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"@originjs/vite-plugin-federation": "^1.4.1",
|
||||
"@types/node": "^24.5.2",
|
||||
"@vue3-oop/plugin-vue-jsx": "^1.5.1",
|
||||
"element-plus": "^2.11.3",
|
||||
"rollup-plugin-visualizer": "^6.0.3",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.1.6",
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/* color palette from <https://github.com/vuejs/theme> */
|
||||
:root {
|
||||
--vt-c-white: #ffffff;
|
||||
--vt-c-white-soft: #f8f8f8;
|
||||
--vt-c-white-mute: #f2f2f2;
|
||||
|
||||
--vt-c-black: #181818;
|
||||
--vt-c-black-soft: #222222;
|
||||
--vt-c-black-mute: #282828;
|
||||
|
||||
--vt-c-indigo: #2c3e50;
|
||||
|
||||
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
|
||||
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
|
||||
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
|
||||
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
|
||||
|
||||
--vt-c-text-light-1: var(--vt-c-indigo);
|
||||
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
|
||||
--vt-c-text-dark-1: var(--vt-c-white);
|
||||
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
|
||||
}
|
||||
|
||||
/* semantic color variables for this project */
|
||||
:root {
|
||||
--color-background: var(--vt-c-white);
|
||||
--color-background-soft: var(--vt-c-white-soft);
|
||||
--color-background-mute: var(--vt-c-white-mute);
|
||||
|
||||
--color-border: var(--vt-c-divider-light-2);
|
||||
--color-border-hover: var(--vt-c-divider-light-1);
|
||||
|
||||
--color-heading: var(--vt-c-text-light-1);
|
||||
--color-text: var(--vt-c-text-light-1);
|
||||
|
||||
--section-gap: 160px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--color-background: var(--vt-c-black);
|
||||
--color-background-soft: var(--vt-c-black-soft);
|
||||
--color-background-mute: var(--vt-c-black-mute);
|
||||
|
||||
--color-border: var(--vt-c-divider-dark-2);
|
||||
--color-border-hover: var(--vt-c-divider-dark-1);
|
||||
|
||||
--color-heading: var(--vt-c-text-dark-1);
|
||||
--color-text: var(--vt-c-text-dark-2);
|
||||
}
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
color: var(--color-text);
|
||||
background: var(--color-background);
|
||||
transition:
|
||||
color 0.5s,
|
||||
background-color 0.5s;
|
||||
line-height: 1.6;
|
||||
font-family:
|
||||
Inter,
|
||||
-apple-system,
|
||||
BlinkMacSystemFont,
|
||||
'Segoe UI',
|
||||
Roboto,
|
||||
Oxygen,
|
||||
Ubuntu,
|
||||
Cantarell,
|
||||
'Fira Sans',
|
||||
'Droid Sans',
|
||||
'Helvetica Neue',
|
||||
sans-serif;
|
||||
font-size: 15px;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>
|
||||
|
Before Width: | Height: | Size: 276 B |
@@ -1,35 +0,0 @@
|
||||
@import './base.css';
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
a,
|
||||
.green {
|
||||
text-decoration: none;
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
transition: 0.4s;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
a:hover {
|
||||
background-color: hsla(160, 100%, 37%, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
body {
|
||||
display: flex;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
#app {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
padding: 0 2rem;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import App from './App'
|
||||
import router from './router'
|
||||
import { init } from "shared/normalize";
|
||||
import element from "shared/element-plus";
|
||||
|
||||
import { initNormalizeStyles } from "shared/normalize";
|
||||
import elementPlus from "shared/element-plus";
|
||||
import { initPubStyles } from 'shared/pub';
|
||||
|
||||
class Main {
|
||||
constructor() {
|
||||
@@ -14,9 +14,10 @@ class Main {
|
||||
.use(router)
|
||||
.mount('#app')
|
||||
|
||||
app.use(element)
|
||||
elementPlus.init(app)
|
||||
|
||||
init()
|
||||
initNormalizeStyles()
|
||||
initPubStyles()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {productRouter} from 'product/ProductRouter'
|
||||
import {RouteRecordRaw} from 'vue-router'
|
||||
import { productRouter } from 'product/ProductRouter'
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
|
||||
const baseRouter: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: () => import('../views/Home'),
|
||||
component: () => import('../views/Home/Home'),
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
name: 'about',
|
||||
component: () => import('../views/About'),
|
||||
component: () => import('../views/About/About'),
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
@@ -21,5 +21,5 @@ const baseRouter: Array<RouteRecordRaw> = [
|
||||
];
|
||||
|
||||
// 聚合所有功能模块的路由
|
||||
const routes: RouteRecordRaw[] = [...baseRouter, ...productRouter];
|
||||
const routes: RouteRecordRaw[] = [ ...baseRouter, ...productRouter ];
|
||||
export default routes;
|
||||
4
front-end/main-app/src/app/views/About/About.module.less
Normal file
4
front-end/main-app/src/app/views/About/About.module.less
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
.About {
|
||||
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import styles from "./About.module.less";
|
||||
|
||||
import { Component, Vue } from 'vue-facing-decorator'
|
||||
|
||||
@Component()
|
||||
export default class About extends Vue {
|
||||
render() {
|
||||
return (
|
||||
<div class="about">
|
||||
<div class={ styles.About }>
|
||||
<h1>我的</h1>
|
||||
</div>
|
||||
)
|
||||
5
front-end/main-app/src/app/views/Home/Home.module.less
Normal file
5
front-end/main-app/src/app/views/Home/Home.module.less
Normal file
@@ -0,0 +1,5 @@
|
||||
.Home {
|
||||
.title {
|
||||
color: var(--theme-color);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import styles from "./Home.module.less";
|
||||
|
||||
import { Component, Ref, Setup, Vue } from 'vue-facing-decorator'
|
||||
import Header from '../components/Header'
|
||||
import Header from '@/components/Header'
|
||||
import { RouteLocationNormalizedLoaded, Router, useRoute, useRouter } from "vue-router";
|
||||
import { ElButton, SearchIcon } from "shared/element-plus";
|
||||
import { ElButton, Icons } from "shared/element-plus";
|
||||
|
||||
|
||||
interface ListItemType {
|
||||
id: number
|
||||
@@ -29,6 +32,7 @@ export default class Home extends Vue {
|
||||
]
|
||||
|
||||
async created() {
|
||||
console.log("import.meta.env: ", import.meta.env)
|
||||
}
|
||||
|
||||
async addCount() {
|
||||
@@ -36,8 +40,6 @@ export default class Home extends Vue {
|
||||
// console.log("ref dom: ", this.refH1)
|
||||
// this.router.push({ name: 'about' })
|
||||
// this.route.query
|
||||
|
||||
|
||||
this.counter++
|
||||
}
|
||||
|
||||
@@ -48,13 +50,19 @@ export default class Home extends Vue {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div class="home">
|
||||
<h1 ref="refH1">首页</h1>
|
||||
<ElButton type="primary" icon={ SearchIcon }>按钮</ElButton>
|
||||
<div class={ styles.Home }>
|
||||
<h1 ref="refH1" class={ styles.title }>首页</h1>
|
||||
<ElButton type="primary" icon={ Icons.Search }>element-plus按钮</ElButton>
|
||||
<p onClick={ this.addCount }>counter 响应式变量(点我):{ this.counter }</p>
|
||||
<Header
|
||||
list={ this.newList }
|
||||
text={ "测试" }>
|
||||
text={ "测试" }
|
||||
// v-slots= { {
|
||||
// default: () => <div class="default">父到子 default 插槽</div>,
|
||||
// haveName: () => <div class="haveName">父到子 具名 插槽</div>,
|
||||
// item: (val: ListItemType) => <li key={ val.id }>{ val.title }</li>
|
||||
// } }
|
||||
>
|
||||
{ {
|
||||
default: () => <div class="default">父到子 default 插槽</div>,
|
||||
haveName: () => <div class="haveName">父到子 具名 插槽</div>,
|
||||
32
front-end/main-app/src/shared/types/shared.d.ts
vendored
32
front-end/main-app/src/shared/types/shared.d.ts
vendored
@@ -1,20 +1,30 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module 'shared/utils' {
|
||||
export const UrlCheckUtils: any;
|
||||
}
|
||||
|
||||
// 2. 为 "shared/element-plus" 模块提供精确的类型声明
|
||||
declare module 'shared/element-plus' {
|
||||
import { App } from "vue";
|
||||
export {
|
||||
ElButton,
|
||||
ElInput,
|
||||
ElTable,
|
||||
ElMessage
|
||||
// 添加其他组件
|
||||
} from 'element-plus';
|
||||
export const initElement: (app: App) => void;
|
||||
export default any;
|
||||
import * as ElementPlus from 'element-plus';
|
||||
import * as ElementPlusIcons from '@element-plus/icons-vue';
|
||||
import type { App } from 'vue';
|
||||
export * from 'element-plus';
|
||||
export import Icons = ElementPlusIcons;
|
||||
|
||||
export function init(app: App): void;
|
||||
|
||||
const defaultExport: typeof ElementPlus & {
|
||||
Icons: typeof ElementPlusIcons;
|
||||
init: typeof init;
|
||||
};
|
||||
export default defaultExport;
|
||||
}
|
||||
|
||||
declare module 'shared/normalize' {
|
||||
export const init: () => void;
|
||||
export const initNormalizeStyles: () => void;
|
||||
}
|
||||
|
||||
declare module 'shared/pub' {
|
||||
export function initPubStyles(): void;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { defineConfig, loadEnv } from 'vite'
|
||||
import vueJsx from '@vue3-oop/plugin-vue-jsx'
|
||||
import federation from '@originjs/vite-plugin-federation';
|
||||
import { nacosRegVitePlugin } from "nacos-federation";
|
||||
import { visualizer } from 'rollup-plugin-visualizer';
|
||||
|
||||
export default defineConfig(async ({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
@@ -18,7 +19,7 @@ export default defineConfig(async ({ mode }) => {
|
||||
return {
|
||||
server: {
|
||||
port: Number(env.VITE_SERVER_PORT),
|
||||
host: '0.0.0.0',
|
||||
host: '::',
|
||||
strictPort: true,
|
||||
},
|
||||
plugins: [
|
||||
@@ -45,6 +46,13 @@ export default defineConfig(async ({ mode }) => {
|
||||
'vue-router': { requiredVersion: '^4.0.6' },
|
||||
pinia: { requiredVersion: '^3.0.3' }
|
||||
}
|
||||
}),
|
||||
visualizer({
|
||||
title: "主应用依赖分析",
|
||||
filename: 'dist/stats.html', // 分析文件输出路径
|
||||
open: false, // 构建完成后自动打开
|
||||
gzipSize: true, // 显示gzip后的大小
|
||||
brotliSize: true, // 显示brotli后的大小
|
||||
})
|
||||
],
|
||||
build: {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^5.6.2",
|
||||
"nacos": "^2.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { NacosConfigClient, NacosNamingClient } from 'nacos';
|
||||
import { formatServiceUrl, getLocalIP } from "./utils";
|
||||
import chalk from 'chalk';
|
||||
|
||||
const logger = console;
|
||||
|
||||
|
||||
export interface RegisterOptions {
|
||||
serverList: string;
|
||||
/** 服务名称(如 'main-app') */
|
||||
@@ -105,6 +105,13 @@ export class nacosServiceManage {
|
||||
});
|
||||
}
|
||||
|
||||
async getConfig(dataId: string, group: string) {
|
||||
const res = await this.configClient.getConfig(dataId, group)
|
||||
console.log()
|
||||
console.log(`${ chalk.blue('[nacos-federation] 配置发现:') }\n ${ chalk.green('➜') } ${ chalk.green(dataId) } 的配置为: ${ chalk.green(res) }`)
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册服务到Nacos并返回客户端实例
|
||||
*/
|
||||
@@ -114,8 +121,8 @@ export class nacosServiceManage {
|
||||
// @ts-ignore
|
||||
await this.nacosClient.registerInstance(serviceName, { port, ip })
|
||||
logger.log()
|
||||
logger.log("[nacos-federation] 服务注册:")
|
||||
logger.log(`服务 ${ serviceName } 已注册到配置中心:${ formatServiceUrl(ip, port) }`);
|
||||
logger.log(chalk.blue("[nacos-federation] 服务注册:"))
|
||||
logger.log(` ${ chalk.green('➜') } ${ chalk.green(serviceName) } (${ formatServiceUrl(ip, port) }) 已注册到配置中心!`);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { loadEnv, Plugin, UserConfig } from 'vite';
|
||||
import { nacosServiceManage, RegisterOptions } from './nacosServiceManage';
|
||||
import chalk from 'chalk';
|
||||
|
||||
const log = console.log;
|
||||
|
||||
export function nacosRegVitePlugin(options?: Partial<RegisterOptions>): Plugin {
|
||||
let nacosInstance: nacosServiceManage | null = null;
|
||||
@@ -21,13 +24,6 @@ export function nacosRegVitePlugin(options?: Partial<RegisterOptions>): Plugin {
|
||||
},
|
||||
async configResolved(config) {
|
||||
|
||||
// 安全检查:确保 config.define 存在
|
||||
if (!config.define) {
|
||||
// @ts-ignore
|
||||
config.define = {};
|
||||
}
|
||||
|
||||
// 从环境变量和配置中获取Nacos配置(环境变量优先级更高)
|
||||
const env = config.env;
|
||||
const registerOptions: RegisterOptions = {
|
||||
serverList: env.VITE_NACOS_ADDRESS || options?.serverList!,
|
||||
@@ -51,13 +47,11 @@ export function nacosRegVitePlugin(options?: Partial<RegisterOptions>): Plugin {
|
||||
// 初始化Nacos实例
|
||||
nacosInstance = await nacosServiceManage.create(registerOptions);
|
||||
|
||||
const baseUrl = await nacosInstance.configClient.getConfig("baseUrl", "DEFAULT_GROUP")
|
||||
|
||||
const baseUrl = await nacosInstance.getConfig("baseUrl", "DEFAULT_GROUP")
|
||||
const baseUrlConfig = baseUrl ? JSON.parse(baseUrl) : {};
|
||||
|
||||
console.log()
|
||||
console.log("[nacos-federation] 配置发现:")
|
||||
console.log("从Nacos配置中心,获得接口地址: ", baseUrlConfig)
|
||||
console.log()
|
||||
baseUrlConfig.httpTimeOut = await nacosInstance.getConfig("httpTimeOut", "DEFAULT_GROUP")
|
||||
|
||||
|
||||
const customizeEnv: Record<string, string> = {};
|
||||
@@ -65,6 +59,7 @@ export function nacosRegVitePlugin(options?: Partial<RegisterOptions>): Plugin {
|
||||
const envKey = `import.meta.env.VITE_${ key.toUpperCase() }`;
|
||||
customizeEnv[envKey] = JSON.stringify(baseUrlConfig[key]);
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
Object.assign(config.define, customizeEnv);
|
||||
Logs(env)
|
||||
@@ -86,16 +81,18 @@ function Logs(env: Record<string, any>) {
|
||||
}
|
||||
}
|
||||
moduleName.length == 0 ? moduleName.push('无') : null
|
||||
console.log()
|
||||
|
||||
console.log(dedentTemplateString(`
|
||||
微服务工具:
|
||||
-> 1:Naco 配置中心: ${ env.VITE_PREFIX }${ env.VITE_NACOS_ADDRESS }
|
||||
-> 2:Traefik 网关: ${ env.VITE_PREFIX }${ env.VITE_TRAEFIK_ADDRESS }
|
||||
${ chalk.blue.bold('微服务工具:') }
|
||||
${ chalk.green('➜') } Naco 配置中心: ${ env.VITE_PREFIX }${ env.VITE_NACOS_ADDRESS }
|
||||
${ chalk.green('➜') } Traefik 网关: ${ env.VITE_PREFIX }${ env.VITE_TRAEFIK_ADDRESS }
|
||||
|
||||
微前端信息:
|
||||
-> 主模块:${ env.VITE_SERVER_NAME }
|
||||
${ chalk.blue.bold('微前端信息:') }
|
||||
${ chalk.green('➜') } 主模块:${ chalk.green(env.VITE_SERVER_NAME) }
|
||||
|
||||
调用模块:
|
||||
-> [ ${ moduleName } ]
|
||||
${ chalk.blue.bold('调用模块:') }
|
||||
${ chalk.green('➜') } [ ${ chalk.yellow(moduleName) } ]
|
||||
`))
|
||||
console.log()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user