From 867ebc52dd7654cb0e41a61d6833461c178d2a28 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 3 Dec 2021 09:53:08 +0100 Subject: [PATCH] fix: register programmatic hooks --- src/build.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/build.ts b/src/build.ts index cd5fab6e..3f2b387a 100644 --- a/src/build.ts +++ b/src/build.ts @@ -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 @@ -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 =>