mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-07 13:14:30 +08:00
refactor: src/game 全部移入 monorepo
This commit is contained in:
1 parent
f7c6434aba
commit
ef8d3e9e2e
54 files changed
+722
-254
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { build, loadConfigFromFile, mergeConfig, UserConfig } from 'vite';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
const outputDir = path.resolve(__dirname, '../dist/game');
|
||||
|
||||
// 清空 dist/game 目录
|
||||
fs.emptyDirSync(outputDir);
|
||||
|
||||
// 构建游戏
|
||||
async function buildGame() {
|
||||
const configFile = path.resolve(__dirname, '../vite.config.ts');
|
||||
const config = await loadConfigFromFile(
|
||||
{ command: 'build', mode: 'production' },
|
||||
configFile
|
||||
);
|
||||
const resolved = mergeConfig(config?.config ?? {}, {
|
||||
build: {
|
||||
outDir: outputDir,
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
input: path.resolve(__dirname, '../src/main.ts'),
|
||||
output: {
|
||||
format: 'es',
|
||||
entryFileNames: '[name].[hash].js',
|
||||
chunkFileNames: 'chunks/[name].[hash].js',
|
||||
assetFileNames: 'assets/[name].[hash][extname]'
|
||||
}
|
||||
}
|
||||
}
|
||||
} satisfies UserConfig);
|
||||
|
||||
await build(resolved);
|
||||
console.log('✅ Game built successfully.');
|
||||
}
|
||||
|
||||
buildGame().catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import { build, loadConfigFromFile, mergeConfig, UserConfig } from 'vite';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
const packagesDir = path.resolve(__dirname, '../packages');
|
||||
const outputDir = path.resolve(__dirname, '../dist/packages');
|
||||
|
||||
// 清空 dist 目录
|
||||
fs.emptyDirSync(outputDir);
|
||||
|
||||
// 获取所有包目录
|
||||
const packageDirs = fs.readdirSync(packagesDir).filter(name => {
|
||||
const packagePath = path.join(packagesDir, name);
|
||||
return fs.statSync(packagePath).isDirectory();
|
||||
});
|
||||
|
||||
// 构建每一个包
|
||||
async function buildPackages() {
|
||||
for (const packageName of packageDirs) {
|
||||
const packageDir = path.join(packagesDir, packageName);
|
||||
const configFile = path.resolve(__dirname, '../vite.config.ts');
|
||||
const config = await loadConfigFromFile(
|
||||
{ command: 'build', mode: 'production' },
|
||||
configFile
|
||||
);
|
||||
const resolved = mergeConfig(config?.config ?? {}, {
|
||||
build: {
|
||||
lib: {
|
||||
entry: path.join(packageDir, 'src/index.ts'),
|
||||
name: packageName,
|
||||
formats: ['es'],
|
||||
fileName: format => `${packageName}.${format}.js`
|
||||
},
|
||||
outDir: path.join(outputDir, packageName),
|
||||
sourcemap: true,
|
||||
emptyOutDir: true,
|
||||
rollupOptions: {
|
||||
external: [/node_modules/, /^@motajs\/.*/]
|
||||
}
|
||||
}
|
||||
} satisfies UserConfig);
|
||||
|
||||
await build(resolved);
|
||||
console.log(`✅ Package ${packageName} built successfully.`);
|
||||
}
|
||||
}
|
||||
|
||||
buildPackages().catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user