From 0b3d637fbf15ecb9414c888a67720c5de463aeb1 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 9 Sep 2021 12:23:53 +0800 Subject: [PATCH] Build: Support build single file (#11469) --- scripts/build/build.mjs | 33 +++++++++++++++++++++++---------- scripts/build/bundler.mjs | 2 +- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/scripts/build/build.mjs b/scripts/build/build.mjs index 1fa3f5a12859..cc7a6c4af7b0 100644 --- a/scripts/build/build.mjs +++ b/scripts/build/build.mjs @@ -150,28 +150,40 @@ async function preparePackage() { } async function run(params) { - await execa("rm", ["-rf", "dist"]); - await execa("mkdir", ["-p", "dist"]); - if (!params.playground) { - await execa("mkdir", ["-p", "dist/esm"]); + const shouldUseCache = !params.file && !params["purge-cache"]; + const shouldPreparePackage = !params.playground && !params.file; + let configs = bundleConfigs; + if (params.file) { + configs = configs.filter(({ output }) => output === params.file); + } else { + await execa("rm", ["-rf", "dist"]); } + await execa("mkdir", ["-p", "dist"]); + await execa("mkdir", ["-p", "dist/esm"]); + if (params["purge-cache"]) { await execa("rm", ["-rf", ".cache"]); } - const bundleCache = new Cache(".cache/", CACHE_VERSION); - await bundleCache.load(); + let bundleCache; + if (shouldUseCache) { + bundleCache = new Cache(".cache/", CACHE_VERSION); + await bundleCache.load(); + } console.log(chalk.inverse(" Building packages ")); - for (const bundleConfig of bundleConfigs) { + + for (const bundleConfig of configs) { await createBundle(bundleConfig, bundleCache, params); } - await cacheFiles(bundleCache); - await bundleCache.save(); + if (shouldUseCache) { + await cacheFiles(bundleCache); + await bundleCache.save(); + } - if (!params.playground) { + if (shouldPreparePackage) { await preparePackage(); } } @@ -179,5 +191,6 @@ async function run(params) { run( minimist(process.argv.slice(2), { boolean: ["purge-cache", "playground", "print-size"], + string: ["file"], }) ); diff --git a/scripts/build/bundler.mjs b/scripts/build/bundler.mjs index b6f402556626..05a2284280f7 100644 --- a/scripts/build/bundler.mjs +++ b/scripts/build/bundler.mjs @@ -376,7 +376,7 @@ async function createBundle(bundle, cache, options) { } if ( - !options["purge-cache"] && + cache && ( await Promise.all( outputOptions.map((outputOption) =>