Commit e460bf4504ad6b200bf1438371abb6e139eec328

Authored by ww
1 parent 830ff573

perf: 新增命令行区分不同环境下运行项目

@@ -8,10 +8,8 @@ VITE_DEV_PATH = '/' @@ -8,10 +8,8 @@ VITE_DEV_PATH = '/'
8 VITE_PRO_PATH = '/' 8 VITE_PRO_PATH = '/'
9 9
10 # spa-title 10 # spa-title
11 -VITE_GLOB_APP_TITLE = GoView 11 +VITE_GLOB_APP_TITLE = Large_Desinger
12 12
13 # spa shortname 13 # spa shortname
14 -VITE_GLOB_APP_SHORT_NAME = GoView  
15 -  
16 -# iot platform proxy prefix  
17 -VITE_IOT_PLATFORM_PROXY_PREFIX = /large-designer/ 14 +# VITE_GLOB_APP_SHORT_NAME =
  15 +
.env.alone.dev renamed from .env.independence
@@ -9,3 +9,6 @@ VITE_GLOB_API_URL_PREFIX = /yt @@ -9,3 +9,6 @@ VITE_GLOB_API_URL_PREFIX = /yt
9 9
10 # 内容安全协议 10 # 内容安全协议
11 VITE_GLOB_CONTENT_SECURITY_POLICY = false 11 VITE_GLOB_CONTENT_SECURITY_POLICY = false
  12 +
  13 +# 公共路径
  14 +VITE_GLOB_PUBLIC_PATH = /
  1 +# Proxy
  2 +VITE_GLOB_PROXY = [["/api", "http://222.180.200.114:48080/api"]]
  3 +
  4 +# Api prefix
  5 +VITE_GLOB_API_URL = /api
  6 +
  7 +#
  8 +VITE_GLOB_API_URL_PREFIX = /yt
  9 +
  10 +# 内容安全协议
  11 +VITE_GLOB_CONTENT_SECURITY_POLICY = false
  12 +
  13 +# 公共路径
  14 +VITE_GLOB_PUBLIC_PATH = /
@@ -8,7 +8,7 @@ VITE_GLOB_API_URL = /api @@ -8,7 +8,7 @@ VITE_GLOB_API_URL = /api
8 VITE_GLOB_API_URL_PREFIX = /yt 8 VITE_GLOB_API_URL_PREFIX = /yt
9 9
10 # 内容安全协议 10 # 内容安全协议
11 -VITE_GLOB_CONTENT_SECURITY_POLICY = false 11 +VITE_GLOB_CONTENT_SECURITY_POLICY = true
12 12
13 # 公共路径 13 # 公共路径
14 -VITE_GLOB_PUBLIC_PATH = / 14 +VITE_GLOB_PUBLIC_PATH = /large-designer/
@@ -7,7 +7,7 @@ VITE_GLOB_API_URL = /api @@ -7,7 +7,7 @@ VITE_GLOB_API_URL = /api
7 VITE_GLOB_API_URL_PREFIX = /yt 7 VITE_GLOB_API_URL_PREFIX = /yt
8 8
9 # 内容安全协议 9 # 内容安全协议
10 -VITE_GLOB_CONTENT_SECURITY_POLICY = true 10 +VITE_GLOB_CONTENT_SECURITY_POLICY = false
11 11
12 -#  
13 -VITE_GLOB_PUBLIC_PATH = / 12 +# 公共路径
  13 +VITE_GLOB_PUBLIC_PATH = /large-designer/
@@ -4,3 +4,4 @@ dist @@ -4,3 +4,4 @@ dist
4 dist-ssr 4 dist-ssr
5 *.local 5 *.local
6 .vscode 6 .vscode
  7 +src/packages/components/Decorates/Mores/external/Icon/SvgBorder.vue
1 import { resolve } from "path" 1 import { resolve } from "path"
2 import { ConfigEnv } from "vite" 2 import { ConfigEnv } from "vite"
3 3
  4 +export enum ProjectRuntimeEnvEnum {
  5 + DEV = 'development',
  6 + PROD = 'production',
  7 + DEV_ALONE = 'alone.dev',
  8 + PROD_ALONE = 'alone.prod'
  9 +}
  10 +
4 export function parseEnv(env: ImportMetaEnv) { 11 export function parseEnv(env: ImportMetaEnv) {
5 const res: Record<string, any> = {} 12 const res: Record<string, any> = {}
6 13
@@ -40,6 +47,6 @@ export function getRootPath(...dir: string[]) { @@ -40,6 +47,6 @@ export function getRootPath(...dir: string[]) {
40 } 47 }
41 48
42 49
43 -export function getPublicPath({ command, mode }: ConfigEnv, viteEnv: ViteEnv) {  
44 - return command === 'build' ? '/' : mode === 'independence' ? viteEnv.VITE_IOT_PLATFORM_PROXY_PREFIX: '/' 50 +export function getPublicPath({ command, mode }: ConfigEnv, viteEnv: ViteEnv) {
  51 + return viteEnv.VITE_GLOB_PUBLIC_PATH
45 } 52 }
@@ -3,9 +3,9 @@ import { createHtmlPlugin } from 'vite-plugin-html' @@ -3,9 +3,9 @@ import { createHtmlPlugin } from 'vite-plugin-html'
3 const GLOB_CONFIG_FILE_NAME = '_app.config.js' 3 const GLOB_CONFIG_FILE_NAME = '_app.config.js'
4 4
5 export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { 5 export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
6 - const { VITE_GLOB_APP_TITLE, VITE_GLOB_CONTENT_SECURITY_POLICY, VITE_GLOB_PUBLIC_PATH } = env 6 + const { VITE_GLOB_APP_TITLE, VITE_GLOB_PUBLIC_PATH } = env
7 const getAppConfigSrc = () => { 7 const getAppConfigSrc = () => {
8 - const path = VITE_GLOB_PUBLIC_PATH?.endsWith('/') ? VITE_GLOB_PUBLIC_PATH : `${VITE_GLOB_PUBLIC_PATH}` 8 + const path = VITE_GLOB_PUBLIC_PATH
9 return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${Date.now()}` 9 return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${Date.now()}`
10 } 10 }
11 11
@@ -14,7 +14,6 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { @@ -14,7 +14,6 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
14 inject: { 14 inject: {
15 data: { 15 data: {
16 title: VITE_GLOB_APP_TITLE, 16 title: VITE_GLOB_APP_TITLE,
17 - contentSecurityPolicy: VITE_GLOB_CONTENT_SECURITY_POLICY ? `<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />` : ''  
18 }, 17 },
19 tags: isBuild ? [ 18 tags: isBuild ? [
20 { 19 {
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html lang="zh-cmn-Hans"> 2 <html lang="zh-cmn-Hans">
3 3
4 -<head>  
5 - <%- contentSecurityPolicy %> 4 +<head>
6 <meta charset="UTF-8" /> 5 <meta charset="UTF-8" />
7 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
8 <meta name="renderer" content="webkit" /> 7 <meta name="renderer" content="webkit" />
@@ -6,9 +6,11 @@ @@ -6,9 +6,11 @@
6 }, 6 },
7 "scripts": { 7 "scripts": {
8 "dev": "vite --host", 8 "dev": "vite --host",
9 - "dev:proxy": "vite --host --mode independence", 9 + "dev:alone": "vite --host --mode alone.dev",
10 "build": "vue-tsc --noEmit && vite build", 10 "build": "vue-tsc --noEmit && vite build",
  11 + "build:alone": "vue-tsc --noEmit && vite build --mode alone.prod",
11 "preview": "vite preview", 12 "preview": "vite preview",
  13 + "preview:alone": "vite preview --mode alone.prod",
12 "new": "plop --plopfile ./plop/plopfile.js", 14 "new": "plop --plopfile ./plop/plopfile.js",
13 "postinstall": "husky install", 15 "postinstall": "husky install",
14 "lint": "eslint --ext .js,.jsx,.ts,.tsx,.vue src", 16 "lint": "eslint --ext .js,.jsx,.ts,.tsx,.vue src",
  1 +import { isBoolean } from "@/utils";
  2 +import { useGlobSetting } from "./setting";
  3 +
  4 +
  5 +let initialFlag = false;
  6 +export function useWebSecurityPolicy() {
  7 + if (window && window.document && window.document.documentElement) {
  8 + const { securityPolicy } = useGlobSetting();
  9 + const flag = isBoolean(securityPolicy) ? securityPolicy : securityPolicy === 'true'
  10 + if (flag && !initialFlag) {
  11 + const meta = document.createElement('meta');
  12 + meta.setAttribute('http-equiv', 'Content-Security-Policy');
  13 + meta.setAttribute('content', 'upgrade-insecure-requests');
  14 + const container = document.querySelector('head');
  15 + container?.prepend(meta);
  16 + initialFlag = true;
  17 + }
  18 + }
  19 +}
@@ -13,8 +13,12 @@ import '@/styles/pages/index.scss' @@ -13,8 +13,12 @@ import '@/styles/pages/index.scss'
13 import 'animate.css/animate.min.css' 13 import 'animate.css/animate.min.css'
14 // 引入标尺 14 // 引入标尺
15 import 'vue3-sketch-ruler/lib/style.css' 15 import 'vue3-sketch-ruler/lib/style.css'
  16 +import { useWebSecurityPolicy } from './hooks/external/useWebSecurityPolicy'
16 17
17 async function appInit() { 18 async function appInit() {
  19 + // THINGS_KIT 内容安全协议hook
  20 + useWebSecurityPolicy()
  21 +
18 const goAppProvider = createApp(GoAppProvider) 22 const goAppProvider = createApp(GoAppProvider)
19 23
20 const app = createApp(App) 24 const app = createApp(App)
@@ -10,7 +10,7 @@ const isIndependenceMode = import.meta.env.MODE === RuntimeEnvironment.INDEPENDE @@ -10,7 +10,7 @@ const isIndependenceMode = import.meta.env.MODE === RuntimeEnvironment.INDEPENDE
10 10
11 const toIotPlatformLogin = () => { 11 const toIotPlatformLogin = () => {
12 const { origin } = window.location 12 const { origin } = window.location
13 - window.location.replace(`${origin}/login?redirect=${import.meta.env.VITE_IOT_PLATFORM_PROXY_PREFIX}`) 13 + window.location.replace(`${origin}/login?redirect=${import.meta.env.VITE_GLOB_PUBLIC_PATH}`)
14 } 14 }
15 15
16 export function createPermissionGuard(router: Router) { 16 export function createPermissionGuard(router: Router) {
@@ -12,10 +12,10 @@ declare interface GlobEnvConfig { @@ -12,10 +12,10 @@ declare interface GlobEnvConfig {
12 12
13 VITE_GLOB_APP_SHORT_NAME: string 13 VITE_GLOB_APP_SHORT_NAME: string
14 } 14 }
15 - 15 +
16 16
17 declare type GlobConfig = { 17 declare type GlobConfig = {
18 - 18 +
19 } 19 }
20 20
21 declare interface ViteEnv extends GlobEnvConfig { 21 declare interface ViteEnv extends GlobEnvConfig {
@@ -25,8 +25,6 @@ declare interface ViteEnv extends GlobEnvConfig { @@ -25,8 +25,6 @@ declare interface ViteEnv extends GlobEnvConfig {
25 VITE_DEV_PATH: string 25 VITE_DEV_PATH: string
26 // 生产地址 26 // 生产地址
27 VITE_PRO_PATH: string 27 VITE_PRO_PATH: string
28 - // iot platform proxy prefix  
29 - VITE_IOT_PLATFORM_PROXY_PREFIX: string  
30 } 28 }
31 29
32 interface ImportMetaEnv extends ViteEnv { 30 interface ImportMetaEnv extends ViteEnv {
@@ -17,7 +17,7 @@ export default defineConfig(({ mode, command }) => { @@ -17,7 +17,7 @@ export default defineConfig(({ mode, command }) => {
17 17
18 const root = process.cwd() 18 const root = process.cwd()
19 19
20 - const env = loadEnv(mode, root) 20 + const env = loadEnv(mode, root)
21 21
22 const viteEnv = parseEnv(env) 22 const viteEnv = parseEnv(env)
23 23
@@ -91,6 +91,6 @@ export default defineConfig(({ mode, command }) => { @@ -91,6 +91,6 @@ export default defineConfig(({ mode, command }) => {
91 server: { 91 server: {
92 port: 5555, 92 port: 5555,
93 proxy: createProxy(viteEnv), 93 proxy: createProxy(viteEnv),
94 - }, 94 + },
95 } 95 }
96 }) 96 })
  1 +import { defineConfig } from 'vite-plugin-windicss';
  2 +export default defineConfig({})