chore: improve build script to only build package when format is valid

This commit is contained in:
Evan You 2025-02-08 17:35:52 +08:00
parent 6a185abbe4
commit ade6ed46dd
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
1 changed files with 11 additions and 0 deletions

View File

@ -173,6 +173,17 @@ async function build(target) {
return return
} }
if (formats) {
let resolvedFormats = formats.split('+')
const pkgFormats = pkg.buildOptions?.formats
if (pkgFormats) {
resolvedFormats = resolvedFormats.filter(f => pkgFormats.includes(f))
}
if (!resolvedFormats.length) {
return
}
}
// if building a specific format, do not remove dist. // if building a specific format, do not remove dist.
if (!formats && existsSync(`${pkgDir}/dist`)) { if (!formats && existsSync(`${pkgDir}/dist`)) {
fs.rmSync(`${pkgDir}/dist`, { recursive: true }) fs.rmSync(`${pkgDir}/dist`, { recursive: true })