chore: 统一各 app 的构建目录

This commit is contained in:
wangxuefeng 2025-03-03 18:22:24 +08:00
parent 7fb8f5b7f8
commit 7c6a86edf6
14 changed files with 102 additions and 180 deletions

View File

@ -49,12 +49,7 @@ export default defineConfig(({ mode }) => {
}, },
build: { build: {
outDir: path.resolve(process.cwd(), '../../dist/designer'), // 输出到根目录/designer outDir: path.resolve(process.cwd(), '../../dist/designer'), // 输出到根目录/designer
emptyOutDir: true, // 构建前清空目录 emptyOutDir: true // 构建前清空目录
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html') // 显式指定入口文件路径
}
}
} }
}; };
}); });

View File

@ -4,5 +4,7 @@ ENV = 'development'
# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path # 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path
VITE_BASE_URL = / VITE_BASE_URL = /
# base api url # 前端可见变量(必须以 VITE_ 开头)
VITE_PORT = 10010
VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/'
VITE_DEBUG_MODE = true

View File

@ -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/'

View File

@ -13,10 +13,9 @@
}, },
"scripts": { "scripts": {
"preinstall": "npx only-allow pnpm", "preinstall": "npx only-allow pnpm",
"serve": "npm run dev", "dev": "cross-env vite --mode development",
"dev": "vite dev", "build": "vite build --mode production",
"build": "rimraf dist && cross-env NODE_ENV=production vite build", "build:staging": "vite build --mode staging",
"build:watch": "rimraf dist && cross-env NODE_ENV=production vite build --watch",
"preview": "vite preview", "preview": "vite preview",
"preview:watch": "npm run build:watch && vite preview", "preview:watch": "npm run build:watch && vite preview",
"clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite", "clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",

View File

@ -17,8 +17,6 @@ import type { UserConfig, ConfigEnv } from 'vite';
// console.log(DEV_SERVER_PORT); // console.log(DEV_SERVER_PORT);
const CWD = process.cwd();
const __APP_INFO__ = { const __APP_INFO__ = {
pkg, pkg,
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
@ -27,12 +25,14 @@ const __APP_INFO__ = {
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => { 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'; const isDev = command === 'serve';
return { return {
define: { define: {
__APP_INFO__: JSON.stringify(__APP_INFO__), __APP_INFO__: JSON.stringify(__APP_INFO__),
// 注入环境变量到客户端
__APP_ENV__: JSON.stringify(env),
}, },
resolve: { resolve: {
alias: [ alias: [
@ -64,7 +64,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
Http2Proxy(), Http2Proxy(),
createSvgIconsPlugin({ createSvgIconsPlugin({
// Specify the icon folder to be cached // Specify the icon folder to be cached
iconDirs: [resolve(CWD, 'src/assets/icons')], iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
// Specify symbolId format // Specify symbolId format
symbolId: 'svg-icon-[dir]-[name]', symbolId: 'svg-icon-[dir]-[name]',
}), }),
@ -119,7 +119,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
}, },
}, },
build: { build: {
outDir: 'dist', outDir: resolve(process.cwd(), '../../dist/platform'), // 输出到根目录/designer
emptyOutDir: true, emptyOutDir: true,
terserOptions: { terserOptions: {
compress: { compress: {

View File

@ -4,5 +4,7 @@ ENV = 'development'
# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path # 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path
VITE_BASE_URL = / VITE_BASE_URL = /
# base api url # 前端可见变量(必须以 VITE_ 开头)
VITE_PORT = 10010
VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/'
VITE_DEBUG_MODE = true

View File

@ -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/'

View File

@ -1,13 +1,16 @@
import { defineConfig } from "@farmfe/core"; import { defineConfig, loadEnv } from "@farmfe/core";
import vue from "@vitejs/plugin-vue"; import vue from "@vitejs/plugin-vue";
import mkcert from "vite-plugin-mkcert"; import mkcert from "vite-plugin-mkcert";
import Http2Proxy from "@sy/vite-plugin-http2-proxy"; import Http2Proxy from "@sy/vite-plugin-http2-proxy";
import path from "path"; import path from "path";
export default defineConfig({ // @ts-ignore
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), ["VITE_"]);
return {
server: { server: {
// 本地开发时允许跨域访问该项目 port: env.VITE_PORT,
port: 10010,
cors: true, cors: true,
}, },
// @ts-ignore // @ts-ignore
@ -19,5 +22,14 @@ export default defineConfig({
$vtj: path.resolve(process.cwd(), ".vtj"), $vtj: path.resolve(process.cwd(), ".vtj"),
}, },
}, },
define: {
// 注入环境变量到客户端
"process.env": JSON.stringify(env),
}, },
output: {
path: path.resolve(process.cwd(), "../../dist/renderer"),
clean: true,
},
},
};
}); });

View File

@ -3,9 +3,9 @@
"version": "1.0.0", "version": "1.0.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "farm dev", "dev": "farm dev --mode development",
"start": "farm start", "start": "farm start --mode production",
"build": "farm build", "build": "farm build --mode production",
"preview": "farm preview", "preview": "farm preview",
"clean:lock": "rimraf pnpm-lock.yaml && rimraf package.lock.json", "clean:lock": "rimraf pnpm-lock.yaml && rimraf package.lock.json",
"clean:lib": "rimraf node_modules", "clean:lib": "rimraf node_modules",

View File

@ -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,
},
},
});

View File

@ -1,5 +1,7 @@
# .env.development # .env.development
VITE_NODE_ENV = pre VITE_NODE_ENV = development
VITE_PORT = 10012
VITE_OA_BASEURL = https://oa-pre.shiyue.com VITE_OA_BASEURL = https://oa-pre.shiyue.com

View File

@ -1,4 +1,4 @@
import { defineConfig } from "@farmfe/core"; import { defineConfig, loadEnv } from "@farmfe/core";
import vue from "@vitejs/plugin-vue"; import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx"; import vueJsx from "@vitejs/plugin-vue-jsx";
import qiankun from "vite-plugin-qiankun"; import qiankun from "vite-plugin-qiankun";
@ -7,22 +7,16 @@ import less from "@farmfe/js-plugin-less";
import Components from "unplugin-vue-components/vite"; import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers"; import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
// const ENVS = { // @ts-ignore
// DEVELOPMENT: "development", export default defineConfig(({ mode }) => {
// PRODUCTION: "production", const env = loadEnv(mode, process.cwd(), ["VITE_"]);
// STAGING: "staging", return {
// TEST: "test",
// };
// const env = process.env.NODE_ENV;
export default defineConfig({
plugins: [less()], plugins: [less()],
vitePlugins: [ vitePlugins: [
vue(), vue(),
vueJsx(), vueJsx(),
qiankun("y-code-app", { qiankun("y-code-app", {
useDevMode: process.env.DEV_ENV === "development", useDevMode: env.VITE_NODE_ENV === "development",
}) as any, }) as any,
Components({ Components({
resolvers: [ resolvers: [
@ -34,13 +28,19 @@ export default defineConfig({
], ],
server: { server: {
cors: true, cors: true,
port: 10012, port: env.VITE_PORT,
}, },
compilation: { compilation: {
resolve: { resolve: {
alias: { alias: {
"@": path.resolve(__dirname, "./src"), "@": path.resolve(__dirname, "./src"),
}, },
}, },
output: {
path: path.resolve(process.cwd(), "../../dist/y-code-v1"),
clean: true,
}, },
},
};
}); });

View File

@ -4,17 +4,10 @@
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
"release": "semantic-release", "dev": "cross-env farm start --mode development",
"dev": "cross-env farm start", "build": "cross-env farm build --mode production",
"build:pre": "cross-env farm build --mode staging", "build:pre": "cross-env farm build --mode staging",
"build:pro": "cross-env farm build --mode production",
"preview": "cross-env farm preview", "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" "clean": "rimraf node_modules"
}, },
"dependencies": { "dependencies": {

View File

@ -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,
},
});