Skip to content

Commit

Permalink
fix: register programmatic hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 3, 2021
1 parent 82d9432 commit 867ebc5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export async function build (rootDir: string, stub: boolean, inputConfig: BuildC

// Read build.config and package.json
const buildConfig: BuildConfig = tryRequire('./build.config', rootDir) || {}
const pkg = tryRequire('./package.json')
const pkg = tryRequire('./package.json', rootDir)

// Resolve preset
let preset = buildConfig.preset || pkg.unbuild?.preset || pkg.build?.preset || inputConfig.preset || {}
if (typeof preset === 'string') {
preset = tryRequire(preset)
preset = tryRequire(preset, rootDir)
}

// Merge options
Expand Down Expand Up @@ -56,12 +56,15 @@ export async function build (rootDir: string, stub: boolean, inputConfig: BuildC
}

// Register hooks
if (buildConfig.hooks) {
ctx.hooks.addHooks(buildConfig.hooks)
}
if (preset.hooks) {
ctx.hooks.addHooks(preset.hooks)
}
if (inputConfig.hooks) {
ctx.hooks.addHooks(inputConfig.hooks)
}
if (buildConfig.hooks) {
ctx.hooks.addHooks(buildConfig.hooks)
}

// Normalize entries
options.entries = options.entries.map(entry =>
Expand Down

0 comments on commit 867ebc5

Please sign in to comment.