实现 nacos 的分布式集群部署配置
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="/src/index.ts" type="module"></script>
|
||||
<script src="/src/main.ts" type="module"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -22,6 +22,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
"@vitejs/plugin-vue-jsx": "^5.1.1",
|
||||
"rollup-plugin-visualizer": "^6.0.3",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.1.6"
|
||||
|
||||
24
front-end/app-shared/src/App.tsx
Normal file
24
front-end/app-shared/src/App.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { defineComponent, onMounted } from 'vue'
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
|
||||
onMounted({})
|
||||
return () => (
|
||||
<>
|
||||
<div class="order-federation-placeholder">
|
||||
<h2>共享资源-联邦模块</h2>
|
||||
<p>此页面仅用于 商品模块 的单独开发和调试,可临时引入组件进行本地测试,实际运行时由 主应用
|
||||
加载本项目代码</p>
|
||||
|
||||
{/*<h2>本模块包含的功能:</h2>*/ }
|
||||
{/*<ul>*/ }
|
||||
{/* <li>1:获取商品首页的数据和展示</li>*/ }
|
||||
{/* <li>2:点击视频进入详情页</li>*/ }
|
||||
{/*</ul>*/ }
|
||||
{/*<p></p>*/ }
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -1,9 +1,9 @@
|
||||
export class HttpConfig {
|
||||
// public static DevBaseUrl: string = "http://127.0.0.1:3210/api"
|
||||
public static DevBaseUrl: string = import.meta.env.VITE_DEVBASEURL
|
||||
public static DevBaseUrl: string = window.__APP_CONFIG__.VITE_DEVBASEURL
|
||||
|
||||
// public static ProdBaseUrl: string = "http://127.0.0.1:3210/api/"
|
||||
public static ProdBaseUrl: string = import.meta.env.VITE_PRODBASEURL
|
||||
|
||||
public static ProdBaseUrl: string = window.__APP_CONFIG__.VITE_PRODBASEURL
|
||||
|
||||
public static apiList: string = ""
|
||||
}
|
||||
|
||||
@@ -7,14 +7,13 @@ import axios, {
|
||||
} from "axios";
|
||||
import { UrlCheckUtils } from '../utils/index'
|
||||
|
||||
|
||||
class AxiosInfra {
|
||||
public instance: AxiosInstance;
|
||||
|
||||
public constructor() {
|
||||
this.instance = axios.create({
|
||||
baseURL: UrlCheckUtils.check(),
|
||||
timeout: Number(import.meta.env.VITE_HTTPTIMEOUT),
|
||||
timeout: Number(window.__APP_CONFIG__.VITE_HTTPTIMEOUT),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
8
front-end/app-shared/src/main.ts
Normal file
8
front-end/app-shared/src/main.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createApp } from 'vue'
|
||||
|
||||
import App from './App'
|
||||
|
||||
|
||||
createApp(App)
|
||||
.mount('#app')
|
||||
|
||||
13
front-end/app-shared/src/types/global.d.ts
vendored
Normal file
13
front-end/app-shared/src/types/global.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface AppConfig {
|
||||
VITE_DEVBASEURL: string;
|
||||
VITE_PRODBASEURL: string;
|
||||
VITE_HTTPTIMEOUT: string;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__APP_CONFIG__: AppConfig;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -16,6 +16,8 @@
|
||||
"DOM",
|
||||
"DOM.Iterable"
|
||||
],
|
||||
"jsx": "preserve",
|
||||
"jsxImportSource": "vue",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"esModuleInterop": true,
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { defineConfig, loadEnv, UserConfig } from 'vite'
|
||||
import federation from "@originjs/vite-plugin-federation";
|
||||
import { nacosRegVitePlugin } from "nacos-federation";
|
||||
// @ts-ignore
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
|
||||
// @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());
|
||||
|
||||
return {
|
||||
base: `${ env.VITE_PREFIX }${ env.VITE_TRAEFIK_ADDRESS }/${ env.VITE_SERVER_NAME }`,
|
||||
server: {
|
||||
port: Number(env.VITE_SERVER_PORT),
|
||||
host: '0.0.0.0',
|
||||
@@ -16,7 +20,7 @@ export default defineConfig(async ({ mode }): Promise<UserConfig> => {
|
||||
cors: true
|
||||
},
|
||||
plugins: [
|
||||
nacosRegVitePlugin(),
|
||||
// nacosRegVitePlugin(),
|
||||
federation({
|
||||
name: env.VITE_SERVER_NAME,
|
||||
exposes: {
|
||||
@@ -34,6 +38,7 @@ export default defineConfig(async ({ mode }): Promise<UserConfig> => {
|
||||
}
|
||||
}),
|
||||
vue(),
|
||||
vueJsx(),
|
||||
visualizer({
|
||||
title: "共享模块依赖分析",
|
||||
filename: 'dist/stats.html', // 分析文件输出路径
|
||||
@@ -47,7 +52,6 @@ export default defineConfig(async ({ mode }): Promise<UserConfig> => {
|
||||
minify: false,
|
||||
cssCodeSplit: true,
|
||||
rollupOptions: {
|
||||
input: './src/index.ts',
|
||||
output: {
|
||||
format: 'esm',
|
||||
minifyInternalExports: false
|
||||
|
||||
Reference in New Issue
Block a user