Showing
16 changed files
with
71 additions
and
25 deletions
| ... | ... | @@ -8,10 +8,8 @@ VITE_DEV_PATH = '/' |
| 8 | 8 | VITE_PRO_PATH = '/' |
| 9 | 9 | |
| 10 | 10 | # spa-title |
| 11 | -VITE_GLOB_APP_TITLE = GoView | |
| 11 | +VITE_GLOB_APP_TITLE = Large_Desinger | |
| 12 | 12 | |
| 13 | 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
.env.alone.prod
0 → 100644
| 1 | 1 | import { resolve } from "path" |
| 2 | 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 | 11 | export function parseEnv(env: ImportMetaEnv) { |
| 5 | 12 | const res: Record<string, any> = {} |
| 6 | 13 | |
| ... | ... | @@ -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 | 3 | const GLOB_CONFIG_FILE_NAME = '_app.config.js' |
| 4 | 4 | |
| 5 | 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 | 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 | 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 | 14 | inject: { |
| 15 | 15 | data: { |
| 16 | 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 | 18 | tags: isBuild ? [ |
| 20 | 19 | { | ... | ... |
| ... | ... | @@ -6,9 +6,11 @@ |
| 6 | 6 | }, |
| 7 | 7 | "scripts": { |
| 8 | 8 | "dev": "vite --host", |
| 9 | - "dev:proxy": "vite --host --mode independence", | |
| 9 | + "dev:alone": "vite --host --mode alone.dev", | |
| 10 | 10 | "build": "vue-tsc --noEmit && vite build", |
| 11 | + "build:alone": "vue-tsc --noEmit && vite build --mode alone.prod", | |
| 11 | 12 | "preview": "vite preview", |
| 13 | + "preview:alone": "vite preview --mode alone.prod", | |
| 12 | 14 | "new": "plop --plopfile ./plop/plopfile.js", |
| 13 | 15 | "postinstall": "husky install", |
| 14 | 16 | "lint": "eslint --ext .js,.jsx,.ts,.tsx,.vue src", | ... | ... |
src/hooks/external/useWebSecurityPolicy.ts
0 → 100644
| 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 | 13 | import 'animate.css/animate.min.css' |
| 14 | 14 | // 引入标尺 |
| 15 | 15 | import 'vue3-sketch-ruler/lib/style.css' |
| 16 | +import { useWebSecurityPolicy } from './hooks/external/useWebSecurityPolicy' | |
| 16 | 17 | |
| 17 | 18 | async function appInit() { |
| 19 | + // THINGS_KIT 内容安全协议hook | |
| 20 | + useWebSecurityPolicy() | |
| 21 | + | |
| 18 | 22 | const goAppProvider = createApp(GoAppProvider) |
| 19 | 23 | |
| 20 | 24 | const app = createApp(App) | ... | ... |
| ... | ... | @@ -10,7 +10,7 @@ const isIndependenceMode = import.meta.env.MODE === RuntimeEnvironment.INDEPENDE |
| 10 | 10 | |
| 11 | 11 | const toIotPlatformLogin = () => { |
| 12 | 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 | 16 | export function createPermissionGuard(router: Router) { | ... | ... |
| ... | ... | @@ -12,10 +12,10 @@ declare interface GlobEnvConfig { |
| 12 | 12 | |
| 13 | 13 | VITE_GLOB_APP_SHORT_NAME: string |
| 14 | 14 | } |
| 15 | - | |
| 15 | + | |
| 16 | 16 | |
| 17 | 17 | declare type GlobConfig = { |
| 18 | - | |
| 18 | + | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | declare interface ViteEnv extends GlobEnvConfig { |
| ... | ... | @@ -25,8 +25,6 @@ declare interface ViteEnv extends GlobEnvConfig { |
| 25 | 25 | VITE_DEV_PATH: string |
| 26 | 26 | // 生产地址 |
| 27 | 27 | VITE_PRO_PATH: string |
| 28 | - // iot platform proxy prefix | |
| 29 | - VITE_IOT_PLATFORM_PROXY_PREFIX: string | |
| 30 | 28 | } |
| 31 | 29 | |
| 32 | 30 | interface ImportMetaEnv extends ViteEnv { | ... | ... |
| ... | ... | @@ -17,7 +17,7 @@ export default defineConfig(({ mode, command }) => { |
| 17 | 17 | |
| 18 | 18 | const root = process.cwd() |
| 19 | 19 | |
| 20 | - const env = loadEnv(mode, root) | |
| 20 | + const env = loadEnv(mode, root) | |
| 21 | 21 | |
| 22 | 22 | const viteEnv = parseEnv(env) |
| 23 | 23 | |
| ... | ... | @@ -91,6 +91,6 @@ export default defineConfig(({ mode, command }) => { |
| 91 | 91 | server: { |
| 92 | 92 | port: 5555, |
| 93 | 93 | proxy: createProxy(viteEnv), |
| 94 | - }, | |
| 94 | + }, | |
| 95 | 95 | } |
| 96 | 96 | }) | ... | ... |
windi.config.ts
0 → 100644