forked from imbytecat/fullstack-starter
refactor: 重构构建流程,提升输出灵活性与配置性
- 移除目标映射表并根据配置前缀生成输出文件名,使构建输出更灵活可配置 - 重构构建任务配置,将原有分步构建逻辑合并为统一的编译任务,明确依赖关系和输出路径
This commit is contained in:
@@ -6,14 +6,6 @@ import { Console, Context, Data, Effect, Layer } from 'effect'
|
||||
// Domain Models & Schema
|
||||
// ============================================================================
|
||||
|
||||
const targetMap = {
|
||||
'bun-windows-x64': 'x86_64-pc-windows-msvc',
|
||||
'bun-darwin-arm64': 'aarch64-apple-darwin',
|
||||
'bun-darwin-x64': 'x86_64-apple-darwin',
|
||||
'bun-linux-x64': 'x86_64-unknown-linux-gnu',
|
||||
'bun-linux-arm64': 'aarch64-unknown-linux-gnu',
|
||||
} as const
|
||||
|
||||
const BunTargetSchema = Schema.Literal(
|
||||
'bun-windows-x64',
|
||||
'bun-darwin-arm64',
|
||||
@@ -22,11 +14,19 @@ const BunTargetSchema = Schema.Literal(
|
||||
'bun-linux-arm64',
|
||||
)
|
||||
|
||||
/**
|
||||
* 将 bun target 转换为文件后缀 (去掉 'bun-' 前缀)
|
||||
*/
|
||||
const getTargetSuffix = (target: BunTarget): string => {
|
||||
return target.replace('bun-', '')
|
||||
}
|
||||
|
||||
type BunTarget = Schema.Schema.Type<typeof BunTargetSchema>
|
||||
|
||||
const BuildConfigSchema = Schema.Struct({
|
||||
entrypoint: Schema.String.pipe(Schema.nonEmptyString()),
|
||||
outputDir: Schema.String.pipe(Schema.nonEmptyString()),
|
||||
outfilePrefix: Schema.String.pipe(Schema.nonEmptyString()),
|
||||
targets: Schema.Array(BunTargetSchema).pipe(Schema.minItems(1)),
|
||||
})
|
||||
|
||||
@@ -94,10 +94,10 @@ class BuildConfigService extends Context.Tag('BuildConfigService')<
|
||||
BuildConfigService,
|
||||
BuildConfigService.fromRaw({
|
||||
entrypoint: '.output/server/index.mjs',
|
||||
// outputDir: 'out',
|
||||
outputDir: 'src-tauri/binaries',
|
||||
outputDir: 'out',
|
||||
outfilePrefix: 'server',
|
||||
targets: ['bun-windows-x64', 'bun-darwin-arm64', 'bun-linux-x64'],
|
||||
}),
|
||||
} satisfies BuildConfig),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ class BuildService extends Context.Tag('BuildService')<
|
||||
Bun.build({
|
||||
entrypoints: [config.entrypoint],
|
||||
compile: {
|
||||
outfile: `app-${targetMap[target]}`,
|
||||
outfile: `${config.outfilePrefix}-${getTargetSuffix(target)}`,
|
||||
target: target,
|
||||
},
|
||||
outdir: config.outputDir,
|
||||
@@ -181,7 +181,7 @@ class BuildService extends Context.Tag('BuildService')<
|
||||
Bun.build({
|
||||
entrypoints: [config.entrypoint],
|
||||
compile: {
|
||||
outfile: `app-${targetMap[target]}`,
|
||||
outfile: `${config.outfilePrefix}-${getTargetSuffix(target)}`,
|
||||
target: target,
|
||||
},
|
||||
outdir: config.outputDir,
|
||||
|
||||
@@ -2,26 +2,9 @@
|
||||
"$schema": "../../node_modules/turbo/schema.json",
|
||||
"extends": ["//"],
|
||||
"tasks": {
|
||||
"build:compile": {
|
||||
"dependsOn": ["build:vite"],
|
||||
"outputs": ["out/**", "src-tauri/binaries/**"]
|
||||
},
|
||||
"build:tauri": {
|
||||
"dependsOn": ["build:compile"],
|
||||
"outputs": ["src-tauri/target/release/bundle/**"]
|
||||
},
|
||||
"build:vite": {
|
||||
"outputs": [".output/**"]
|
||||
},
|
||||
"dev:tauri": {
|
||||
"cache": false,
|
||||
"dependsOn": ["build:compile"],
|
||||
"persistent": true,
|
||||
"with": ["dev:vite"]
|
||||
},
|
||||
"dev:vite": {
|
||||
"cache": false,
|
||||
"persistent": true
|
||||
"compile": {
|
||||
"dependsOn": ["build"],
|
||||
"outputs": ["out/**"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user