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: {
outDir: path.resolve(process.cwd(), '../../dist/designer'), // 输出到根目录/designer
emptyOutDir: true, // 构建前清空目录
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html') // 显式指定入口文件路径
}
}
emptyOutDir: true // 构建前清空目录
}
};
});

View File

@ -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/'
# 前端可见变量(必须以 VITE_ 开头)
VITE_PORT = 10010
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": {
"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",

View File

@ -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: {

View File

@ -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/'
# 前端可见变量(必须以 VITE_ 开头)
VITE_PORT = 10010
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,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,
},
},
},
};
});

View File

@ -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",

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
VITE_NODE_ENV = pre
VITE_NODE_ENV = development
VITE_PORT = 10012
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 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,
},
},
},
};
});

View File

@ -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": {

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