将vite.config.ts中的base 改到插件 nacos-federation中实现,简化代码
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
# 请求协议 http or https(建议线上配置证书后,使用https)
|
||||
VITE_PREFIX=http://
|
||||
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# 请求协议 http or https(建议线上配置证书后,使用https)
|
||||
VITE_PREFIX=http://
|
||||
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ export default defineConfig(async ({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
|
||||
return {
|
||||
base: `http://${ env.VITE_TRAEFIK_ADDRESS }/${ env.VITE_SERVER_NAME }/`,
|
||||
server: {
|
||||
port: Number(env.VITE_SERVER_PORT),
|
||||
host: '0.0.0.0',
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# 请求协议 http or https(建议线上配置证书后,使用https)
|
||||
VITE_PREFIX=http://
|
||||
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# 请求协议 http or https(建议线上配置证书后,使用https)
|
||||
VITE_PREFIX=http://
|
||||
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ export default defineConfig(async ({ mode }): Promise<UserConfig> => {
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
|
||||
return {
|
||||
base: `http://${ env.VITE_TRAEFIK_ADDRESS }/${ env.VITE_SERVER_NAME }/`,
|
||||
server: {
|
||||
port: Number(env.VITE_SERVER_PORT),
|
||||
host: '0.0.0.0',
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# 请求协议 http or https(建议线上配置证书后,使用https)
|
||||
VITE_PREFIX=http://
|
||||
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
# 请求协议 http or https(建议线上配置证书后,使用https)
|
||||
VITE_PREFIX=http://
|
||||
|
||||
# Nacos 配置中心ip:端口
|
||||
VITE_NACOS_ADDRESS=192.168.31.101:8848
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Plugin } from 'vite';
|
||||
import { loadEnv, Plugin, UserConfig } from 'vite';
|
||||
import { nacosServiceManage, RegisterOptions } from './nacosServiceManage';
|
||||
|
||||
export function nacosRegVitePlugin(options?: Partial<RegisterOptions>): Plugin {
|
||||
@@ -6,6 +6,13 @@ export function nacosRegVitePlugin(options?: Partial<RegisterOptions>): Plugin {
|
||||
|
||||
return {
|
||||
name: 'vite-plugin-nacos',
|
||||
async config(userConfig: UserConfig, { mode }) {
|
||||
// 修改base,增加资源来源地址,修复资源错误加载的问题
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
return {
|
||||
base: `${ env.VITE_PREFIX }${ env.VITE_TRAEFIK_ADDRESS }/${ env.VITE_SERVER_NAME }/`,
|
||||
}
|
||||
},
|
||||
async configResolved(config) {
|
||||
|
||||
// 安全检查:确保 config.define 存在
|
||||
|
||||
Reference in New Issue
Block a user