diff --git a/apps/designer/vite.config.ts b/apps/designer/vite.config.ts index ffd6495..16f9a3e 100644 --- a/apps/designer/vite.config.ts +++ b/apps/designer/vite.config.ts @@ -49,12 +49,7 @@ export default defineConfig(({ mode }) => { }, build: { outDir: path.resolve(process.cwd(), '../../dist/designer'), // 输出到根目录/designer - emptyOutDir: true, // 构建前清空目录 - rollupOptions: { - input: { - main: path.resolve(__dirname, 'index.html') // 显式指定入口文件路径 - } - } + emptyOutDir: true // 构建前清空目录 } }; }); diff --git a/apps/platform/.env.development b/apps/platform/.env.development index c440086..2ce3ad5 100644 --- a/apps/platform/.env.development +++ b/apps/platform/.env.development @@ -4,5 +4,7 @@ ENV = 'development' # 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path VITE_BASE_URL = / -# base api url -VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' \ No newline at end of file +# 前端可见变量(必须以 VITE_ 开头) +VITE_PORT = 10010 +VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' +VITE_DEBUG_MODE = true \ No newline at end of file diff --git a/apps/platform/.env.staging b/apps/platform/.env.staging new file mode 100644 index 0000000..7582267 --- /dev/null +++ b/apps/platform/.env.staging @@ -0,0 +1,8 @@ +# 只在预发布模式中被载入 +ENV = 'staging' + +# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path +VITE_BASE_URL = / + +# base api url +VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' \ No newline at end of file diff --git a/apps/platform/package.json b/apps/platform/package.json index 4d0c7dd..2a8ede6 100644 --- a/apps/platform/package.json +++ b/apps/platform/package.json @@ -13,10 +13,9 @@ }, "scripts": { "preinstall": "npx only-allow pnpm", - "serve": "npm run dev", - "dev": "vite dev", - "build": "rimraf dist && cross-env NODE_ENV=production vite build", - "build:watch": "rimraf dist && cross-env NODE_ENV=production vite build --watch", + "dev": "cross-env vite --mode development", + "build": "vite build --mode production", + "build:staging": "vite build --mode staging", "preview": "vite preview", "preview:watch": "npm run build:watch && vite preview", "clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite", diff --git a/apps/platform/vite.config.ts b/apps/platform/vite.config.ts index 028fe5b..0ab050f 100644 --- a/apps/platform/vite.config.ts +++ b/apps/platform/vite.config.ts @@ -17,8 +17,6 @@ import type { UserConfig, ConfigEnv } from 'vite'; // console.log(DEV_SERVER_PORT); -const CWD = process.cwd(); - const __APP_INFO__ = { pkg, lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), @@ -27,12 +25,14 @@ const __APP_INFO__ = { // https://vitejs.dev/config/ export default ({ command, mode }: ConfigEnv): UserConfig => { // 环境变量 - const { VITE_BASE_API_URL, VITE_BASE_URL, ENV } = loadEnv(mode, CWD); + const env = loadEnv(mode, process.cwd(), ['VITE_', 'VTJ_', 'SY_']); const isDev = command === 'serve'; return { define: { __APP_INFO__: JSON.stringify(__APP_INFO__), + // 注入环境变量到客户端 + __APP_ENV__: JSON.stringify(env), }, resolve: { alias: [ @@ -64,7 +64,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { Http2Proxy(), createSvgIconsPlugin({ // Specify the icon folder to be cached - iconDirs: [resolve(CWD, 'src/assets/icons')], + iconDirs: [resolve(process.cwd(), 'src/assets/icons')], // Specify symbolId format symbolId: 'svg-icon-[dir]-[name]', }), @@ -119,7 +119,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { }, }, build: { - outDir: 'dist', + outDir: resolve(process.cwd(), '../../dist/platform'), // 输出到根目录/designer emptyOutDir: true, terserOptions: { compress: { diff --git a/apps/renderer/.env.development b/apps/renderer/.env.development index c440086..2ce3ad5 100644 --- a/apps/renderer/.env.development +++ b/apps/renderer/.env.development @@ -4,5 +4,7 @@ ENV = 'development' # 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path VITE_BASE_URL = / -# base api url -VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' \ No newline at end of file +# 前端可见变量(必须以 VITE_ 开头) +VITE_PORT = 10010 +VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' +VITE_DEBUG_MODE = true \ No newline at end of file diff --git a/apps/renderer/.env.staging b/apps/renderer/.env.staging new file mode 100644 index 0000000..7582267 --- /dev/null +++ b/apps/renderer/.env.staging @@ -0,0 +1,8 @@ +# 只在预发布模式中被载入 +ENV = 'staging' + +# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path +VITE_BASE_URL = / + +# base api url +VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' \ No newline at end of file diff --git a/apps/renderer/farm.config.ts b/apps/renderer/farm.config.ts index 59eda5f..883a3db 100644 --- a/apps/renderer/farm.config.ts +++ b/apps/renderer/farm.config.ts @@ -1,23 +1,35 @@ -import { defineConfig } from "@farmfe/core"; +import { defineConfig, loadEnv } from "@farmfe/core"; import vue from "@vitejs/plugin-vue"; import mkcert from "vite-plugin-mkcert"; import Http2Proxy from "@sy/vite-plugin-http2-proxy"; import path from "path"; -export default defineConfig({ - server: { - // 本地开发时允许跨域访问该项目 - port: 10010, - cors: true, - }, - // @ts-ignore - vitePlugins: [vue(), mkcert({ source: "coding" }), Http2Proxy()], - compilation: { - resolve: { - alias: { - "@": path.resolve(process.cwd(), "src"), - $vtj: path.resolve(process.cwd(), ".vtj"), +// @ts-ignore +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ["VITE_"]); + + return { + server: { + port: env.VITE_PORT, + cors: true, + }, + // @ts-ignore + vitePlugins: [vue(), mkcert({ source: "coding" }), Http2Proxy()], + compilation: { + resolve: { + alias: { + "@": path.resolve(process.cwd(), "src"), + $vtj: path.resolve(process.cwd(), ".vtj"), + }, + }, + define: { + // 注入环境变量到客户端 + "process.env": JSON.stringify(env), + }, + output: { + path: path.resolve(process.cwd(), "../../dist/renderer"), + clean: true, }, }, - }, + }; }); diff --git a/apps/renderer/package.json b/apps/renderer/package.json index 6eca448..ada64cc 100644 --- a/apps/renderer/package.json +++ b/apps/renderer/package.json @@ -3,9 +3,9 @@ "version": "1.0.0", "type": "module", "scripts": { - "dev": "farm dev", - "start": "farm start", - "build": "farm build", + "dev": "farm dev --mode development", + "start": "farm start --mode production", + "build": "farm build --mode production", "preview": "farm preview", "clean:lock": "rimraf pnpm-lock.yaml && rimraf package.lock.json", "clean:lib": "rimraf node_modules", diff --git a/apps/renderer/vite.config.ts b/apps/renderer/vite.config.ts deleted file mode 100644 index 91b09d9..0000000 --- a/apps/renderer/vite.config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { defineConfig } from "vite"; -import http2Proxy from "@sy/vite-plugin-http2-proxy"; -import mkcert from "vite-plugin-mkcert"; -import VuePlugin from "@vitejs/plugin-vue"; - -export default defineConfig({ - server: { - port: 10010, - }, - plugins: [http2Proxy(), mkcert(), VuePlugin()], - esbuild: { - supported: { - "top-level-await": true, - }, - }, -}); diff --git a/apps/y-code-v1/.env.development b/apps/y-code-v1/.env.development index 1e96b37..68252f4 100644 --- a/apps/y-code-v1/.env.development +++ b/apps/y-code-v1/.env.development @@ -1,5 +1,7 @@ # .env.development -VITE_NODE_ENV = pre +VITE_NODE_ENV = development + +VITE_PORT = 10012 VITE_OA_BASEURL = https://oa-pre.shiyue.com diff --git a/apps/y-code-v1/farm.config.ts b/apps/y-code-v1/farm.config.ts index daf11e4..6115e9d 100644 --- a/apps/y-code-v1/farm.config.ts +++ b/apps/y-code-v1/farm.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from "@farmfe/core"; +import { defineConfig, loadEnv } from "@farmfe/core"; import vue from "@vitejs/plugin-vue"; import vueJsx from "@vitejs/plugin-vue-jsx"; import qiankun from "vite-plugin-qiankun"; @@ -7,40 +7,40 @@ import less from "@farmfe/js-plugin-less"; import Components from "unplugin-vue-components/vite"; import { AntDesignVueResolver } from "unplugin-vue-components/resolvers"; -// const ENVS = { -// DEVELOPMENT: "development", -// PRODUCTION: "production", -// STAGING: "staging", -// TEST: "test", -// }; +// @ts-ignore +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ["VITE_"]); + return { + plugins: [less()], + vitePlugins: [ + vue(), + vueJsx(), + qiankun("y-code-app", { + useDevMode: env.VITE_NODE_ENV === "development", + }) as any, + Components({ + resolvers: [ + AntDesignVueResolver({ + importStyle: "less", + }), + ], + }), + ], + server: { + cors: true, + port: env.VITE_PORT, + }, -// const env = process.env.NODE_ENV; - -export default defineConfig({ - plugins: [less()], - vitePlugins: [ - vue(), - vueJsx(), - qiankun("y-code-app", { - useDevMode: process.env.DEV_ENV === "development", - }) as any, - Components({ - resolvers: [ - AntDesignVueResolver({ - importStyle: "less", - }), - ], - }), - ], - server: { - cors: true, - port: 10012, - }, - compilation: { - resolve: { - alias: { - "@": path.resolve(__dirname, "./src"), + compilation: { + resolve: { + alias: { + "@": path.resolve(__dirname, "./src"), + }, + }, + output: { + path: path.resolve(process.cwd(), "../../dist/y-code-v1"), + clean: true, }, }, - }, + }; }); diff --git a/apps/y-code-v1/package.json b/apps/y-code-v1/package.json index 05fee6b..adf99d7 100644 --- a/apps/y-code-v1/package.json +++ b/apps/y-code-v1/package.json @@ -4,17 +4,10 @@ "private": true, "type": "module", "scripts": { - "release": "semantic-release", - "dev": "cross-env farm start", + "dev": "cross-env farm start --mode development", + "build": "cross-env farm build --mode production", "build:pre": "cross-env farm build --mode staging", - "build:pro": "cross-env farm build --mode production", "preview": "cross-env farm preview", - "vite:dev": "cross-env DEV_ENV=development vite --mode staging", - "vite:pro": "cross-env DEV_ENV=development vite --mode production", - "vite:build:pre": "vite build --mode staging", - "vite:build:pro": "vite build --mode production", - "type-check": "vue-tsc --build --force", - "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", "clean": "rimraf node_modules" }, "dependencies": { diff --git a/apps/y-code-v1/vite.config.ts b/apps/y-code-v1/vite.config.ts deleted file mode 100644 index 66af1e7..0000000 --- a/apps/y-code-v1/vite.config.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { fileURLToPath, URL } from "node:url"; -import { defineConfig } from "vite"; -import vue from "@vitejs/plugin-vue"; -import vueJsx from "@vitejs/plugin-vue-jsx"; -import Components from "unplugin-vue-components/vite"; -import { AntDesignVueResolver } from "unplugin-vue-components/resolvers"; -import qiankun from "vite-plugin-qiankun"; -import yargsParser from "yargs-parser"; - -const argv = yargsParser(process.argv.slice(2)); - -console.log(process.env.DEV_ENV); - -let base: string; -switch (argv.mode) { - case "staging": - case "test": - base = "https://custom-chart.shiyue.com/"; - break; - case "production": - base = "https://custom-chart.shiyuegame.com/"; - break; - default: - base = "http://localhost:8080/"; -} -if (process.env.DEV_ENV === "development") { - base = "http://localhost:8080/"; -} - -// https://vitejs.dev/config/ -export default defineConfig({ - build: { - sourcemap: false, - rollupOptions: { - output: { - assetFileNames: "[name]-ycode-[hash:8].[ext]", - chunkFileNames: "[name]-ycode-[hash:8].js", - entryFileNames: "[name]-ycode-[hash:8].js", - }, - }, - }, - css: { - devSourcemap: true, - preprocessorOptions: { - less: { - modifyVars: { - "ant-prefix": "ycode-ant", - }, - }, - }, - }, - plugins: [ - vue(), - vueJsx(), - Components({ - resolvers: [ - AntDesignVueResolver({ - importStyle: "less", - }), - ], - }), - qiankun("y-code-app", { - useDevMode: process.env.DEV_ENV === "development", - }), - ], - resolve: { - alias: { - "@": fileURLToPath(new URL("./src", import.meta.url)), - }, - }, - base, - define: { - _BASE_HOST_: `'${base}'`, - }, - optimizeDeps: { - force: true, // 强制重新预构建依赖 - }, - server: { - hmr: true, - host: "0.0.0.0", - port: 8080, - }, -});