Skip to content

Commit

Permalink
Build: Support build single file (#11469)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Sep 9, 2021
1 parent 1c4da1e commit 62a2629
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions scripts/build/build.mjs
Expand Up @@ -150,34 +150,47 @@ 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();
}
}

run(
minimist(process.argv.slice(2), {
boolean: ["purge-cache", "playground", "print-size"],
string: ["file"],
})
);
2 changes: 1 addition & 1 deletion scripts/build/bundler.mjs
Expand Up @@ -376,7 +376,7 @@ async function createBundle(bundle, cache, options) {
}

if (
!options["purge-cache"] &&
cache &&
(
await Promise.all(
outputOptions.map((outputOption) =>
Expand Down

0 comments on commit 62a2629

Please sign in to comment.