build: further shave off runtime compile only code

This commit is contained in:
Evan You
2019-10-14 01:08:00 -04:00
parent 57a94b530d
commit 82b5978e9c
7 changed files with 36 additions and 17 deletions

View File

@@ -28,8 +28,12 @@ const formats = args.formats || args.f
const devOnly = args.devOnly || args.d
const prodOnly = !devOnly && (args.prodOnly || args.p)
const buildAllMatching = args.all || args.a
const lean = args.lean || args.l
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
;(async () => {
run()
async function run() {
if (!targets.length) {
await buildAll(allTargets)
checkAllSizes(allTargets)
@@ -37,7 +41,7 @@ const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
await buildAll(fuzzyMatchTarget(targets, buildAllMatching))
checkAllSizes(fuzzyMatchTarget(targets, buildAllMatching))
}
})()
}
async function buildAll(targets) {
for (const target of targets) {
@@ -54,7 +58,6 @@ async function build(target) {
const env =
(pkg.buildOptions && pkg.buildOptions.env) ||
(devOnly ? 'development' : 'production')
await execa(
'rollup',
[
@@ -66,7 +69,8 @@ async function build(target) {
`TARGET:${target}`,
formats ? `FORMATS:${formats}` : ``,
args.types ? `TYPES:true` : ``,
prodOnly ? `PROD_ONLY:true` : ``
prodOnly ? `PROD_ONLY:true` : ``,
lean ? `LEAN:true` : ``
]
.filter(Boolean)
.join(',')
@@ -118,7 +122,7 @@ function checkAllSizes(targets) {
function checkSize(target) {
const pkgDir = path.resolve(`packages/${target}`)
const esmProdBuild = `${pkgDir}/dist/${target}.esm-browser.prod.js`
const esmProdBuild = `${pkgDir}/dist/${target}.global.prod.js`
if (fs.existsSync(esmProdBuild)) {
const file = fs.readFileSync(esmProdBuild)
const minSize = (file.length / 1024).toFixed(2) + 'kb'