From f9de7b5d6a7d415f2282243b02c75ba62aede53c Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Sep 2021 18:42:04 +0800 Subject: [PATCH 1/2] Build: support build single file --- 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..f8355c11eedd 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 shouldBuildMetaFiles = !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 (shouldBuildMetaFiles) { 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) => From 755e2bc5bac0b47500a4a816ad29face1a506335 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Sep 2021 23:57:20 +0800 Subject: [PATCH 2/2] Rename variable. --- scripts/build/build.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build/build.mjs b/scripts/build/build.mjs index f8355c11eedd..cc7a6c4af7b0 100644 --- a/scripts/build/build.mjs +++ b/scripts/build/build.mjs @@ -151,7 +151,7 @@ async function preparePackage() { async function run(params) { const shouldUseCache = !params.file && !params["purge-cache"]; - const shouldBuildMetaFiles = !params.playground && !params.file; + const shouldPreparePackage = !params.playground && !params.file; let configs = bundleConfigs; if (params.file) { configs = configs.filter(({ output }) => output === params.file); @@ -183,7 +183,7 @@ async function run(params) { await bundleCache.save(); } - if (shouldBuildMetaFiles) { + if (shouldPreparePackage) { await preparePackage(); } }