-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
import { mkdist } from 'mkdist' | ||
import { mkdist, MkdistOptions } from 'mkdist' | ||
import { symlink, rmdir } from '../utils' | ||
import type { BuildContext } from '../types' | ||
|
||
import type { BuildEntry, BuildContext } from '../types' | ||
export async function mkdistBuild (ctx: BuildContext) { | ||
for (const entry of ctx.options.entries.filter(e => e.builder === 'mkdist')) { | ||
type MkdistEntry = BuildEntry & { builder: 'mkdist' } | ||
const entries = ctx.options.entries.filter(e => e.builder === 'mkdist') as MkdistEntry[] | ||
await ctx.hooks.callHook('mkdist:before', ctx, entries) | ||
for (const entry of entries) { | ||
const distDir = entry.outDir! | ||
if (ctx.options.stub) { | ||
await rmdir(distDir) | ||
await symlink(entry.input, distDir) | ||
} else { | ||
const { writtenFiles } = await mkdist({ | ||
const mkdistOptions: MkdistOptions = { | ||
rootDir: ctx.options.rootDir, | ||
srcDir: entry.input, | ||
distDir, | ||
format: entry.format, | ||
cleanDist: false, | ||
declaration: entry.declaration, | ||
// @ts-ignore | ||
ext: entry.ext | ||
}) | ||
} | ||
await ctx.hooks.callHook('mkdist:options', ctx, mkdistOptions) | ||
const output = await mkdist(mkdistOptions) | ||
ctx.buildEntries.push({ | ||
path: distDir, | ||
chunks: [`${writtenFiles.length} files`] | ||
chunks: [`${output.writtenFiles.length} files`] | ||
}) | ||
await ctx.hooks.callHook('mkdist:build', ctx, output) | ||
} | ||
} | ||
await ctx.hooks.callHook('mkdist:done', ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters