Skip to content

⬅️ Back to Table of Contents

📄 export-size.ts

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 8
📊 Variables & Constants 2
⚡ Async/Await Patterns 1

📚 Table of Contents

🛠️ File Location:

📂 scripts/export-size.ts

📦 Imports

Name Source
join node:path
resolve node:path
fileURLToPath node:url
getExportsSize export-size
filesize filesize
markdownTable markdown-table
packages ../meta/packages
version ../package.json

Variables & Constants

Name Type Kind Value Exported
md string let/var '# Export size\n\n'
mdJSON { [name: string]: string; } let/var <{ [name: string]: string }>{}

Async/Await Patterns

Type Function Await Expressions Promise Chains
async-function run fs.writeFile(join(packagesRoot, 'shared/index.mjs'), 'export * from "./dist/index.mjs"', 'utf-8'), fs.writeFile(join(packagesRoot, 'core/index.mjs'), 'export * from "./dist/index.mjs"', 'utf-8'), getExportsSize({
pkg: ./packages/${pkg.name}/dist,
output: false,
bundler: 'rollup',
external: ['vue', ...(pkg.external [])],
includes: ['@vueuse/shared'],
}), fs.rm(join(packagesRoot, 'shared/index.mjs'), { force: true }), fs.rm(join(packagesRoot, 'core/index.mjs'), { force: true }), fs.writeFile('packages/export-size.md', md, 'utf-8'), fs.writeFile('packages/export-size.json', ${JSON.stringify(mdJSON, null, 2)}\n) none

Functions

run(): Promise<void>

Code
async function run() {
  // made shared library imported can resolve correctly
  const packagesRoot = resolve(__dirname, '..', 'packages')
  await fs.writeFile(join(packagesRoot, 'shared/index.mjs'), 'export * from "./dist/index.mjs"', 'utf-8')
  await fs.writeFile(join(packagesRoot, 'core/index.mjs'), 'export * from "./dist/index.mjs"', 'utf-8')

  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}/dist`,
      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.rm(join(packagesRoot, 'shared/index.mjs'), { force: true })
  await fs.rm(join(packagesRoot, 'core/index.mjs'), { force: true })
  await fs.writeFile('packages/export-size.md', md, 'utf-8')
  await fs.writeFile('packages/export-size.json', `${JSON.stringify(mdJSON, null, 2)}\n`)
}
  • Return Type: Promise<void>
  • Calls:
  • resolve (from node:path)
  • fs.writeFile
  • join (from node:path)
  • new Date().toISOString
  • packages.slice
  • getExportsSize (from export-size)
  • markdownTable (from markdown-table)
  • exports.map
  • filesize (from filesize)
  • md.replace
  • fs.rm
  • JSON.stringify
  • Internal Comments:
    // made shared library imported can resolve correctly (x2)