Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: support build single file #11469

Merged
merged 3 commits into from Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"]);

This comment was marked as resolved.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters to make an empty dir.


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