Skip to content

⬅️ Back to Table of Contents

📄 export-size

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 5
⚡ Async/Await Patterns 1

📚 Table of Contents

🛠️ File Location:

📂 scripts/export-size.ts

📦 Imports

Name Source
getExportsSize export-size
filesize filesize
markdownTable markdown-table
packages ../meta/packages
version ../package.json

Async/Await Patterns

Type Function Await Expressions Promise Chains
async-function run getExportsSize({ pkg: ./packages/${pkg.name}, output: false, bundler: 'roll... none

Functions

run(): Promise<void>

Returns: Promise<void>

Calls:

  • new Date().toISOString
  • packages.slice
  • getExportsSize (from export-size)
  • markdownTable (from markdown-table)
  • exports.map
  • filesize (from filesize)
  • md.replace
  • fs.writeFile
  • JSON.stringify
Code
async function run() {
  let md = '# Export size\n\n'
  const mdJSON = <{ [name: string]: string }>{}
  md += 'generated by [export-size](https://github.com/antfu/export-size)<br>\n'
  md += `version: ${version}<br>\n`
  md += `date: ${new Date().toISOString()}\n\n`

  md += '> Please note this is bundle size for each individual APIs (excluding Vue). '
  md += 'Since we have a lot shared utilities underneath each function, importing two '
  md += 'different functions does NOT necessarily mean the bundle size will be the sum of them (usually smaller). '
  md += 'Depends on the bundler and minifier you use, the final result might vary, this list is for reference only.'
  md += '\n\n'

  for (const pkg of [...packages.slice(2), packages[1]]) {
    const { exports, packageJSON } = await getExportsSize({
      pkg: `./packages/${pkg.name}`,
      output: false,
      bundler: 'rollup',
      external: ['vue', ...(pkg.external || [])],
      includes: ['@vueuse/shared'],
    })

    md += `<kbd>${packageJSON.name}</kbd>\n\n`

    md += markdownTable([
      ['Function', 'min+gzipped'],
      ...exports.map((i) => {
        mdJSON[i.name] = filesize(i.minzipped)
        return [`\`${i.name}\``, filesize(i.minzipped)]
      }),
    ])

    md += '\n\n'
  }

  md = md.replace(/\r\n/g, '\n')

  await fs.writeFile('packages/export-size.md', md, 'utf-8')
  await fs.writeFile('packages/export-size.json', `${JSON.stringify(mdJSON, null, 2)}\n`)
}

Generated by Syntax Scribe