idraw/scripts/build-bundle.ts

46 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2022-12-31 15:21:57 +00:00
import { build } from 'vite';
import type { InlineConfig } from 'vite';
2022-12-31 15:29:45 +00:00
import { joinPackagePath } from './util/project';
2022-12-31 15:21:57 +00:00
import { packages } from './config';
async function buildBundle(opts: { dirName: string; globalName: string }) {
const { dirName, globalName } = opts;
2022-12-31 15:29:45 +00:00
const filePath = joinPackagePath(dirName, 'src', 'index.ts');
const distDir = joinPackagePath(dirName, 'dist');
2022-12-31 15:21:57 +00:00
const config: InlineConfig = {
plugins: [],
build: {
minify: false,
emptyOutDir: false,
lib: {
name: globalName,
entry: filePath,
formats: ['iife'],
fileName: () => {
return 'index.global.js';
}
},
outDir: distDir
2025-09-06 05:16:34 +00:00
},
resolve: {
alias: {
'@idraw/util': joinPackagePath('util', 'src', 'index.ts'),
'@idraw/renderer': joinPackagePath('renderer', 'src', 'index.ts'),
'@idraw/core': joinPackagePath('core', 'src', 'index.ts')
}
2022-12-31 15:21:57 +00:00
}
};
console.log(`Start build bundle [${dirName}] ...`);
await build(config);
console.log(`Build bundle [${dirName}] successfully!`);
}
async function run() {
for (let i = 0; i < packages.length; i++) {
const pkg = packages[i];
await buildBundle(pkg);
}
}
run();