#discord-api-types and tree-shaking

4 messages · Page 1 of 1 (latest)

vale spear

using esbuild@0.20.0 and discord-api-types@0.37.69, is there a proper way to tree-shake it so I actually only get the code I use?
running npx esbuild index.ts --bundle --minify --outfile=index.js with the snippet below, I get a 69.1kb file, which is not negligible when working with space constrained envs like cloudflare workers

import { InteractionType } from 'discord-api-types/v10'

console.log(InteractionType.Ping)
peak radishBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
vale spear

like to contrast, writing this workaround results in only 147 bytes, which is 470x smaller

import type { InteractionType as _InteractionType } from 'discord-api-types/v10'

const InteractionType = {
  Ping: 1,
  ApplicationCommand: 2,
  MessageComponent: 3,
  ApplicationCommandAutocomplete: 4,
  ModalSubmit: 5,
} as unknown as typeof _InteractionType

console.log(InteractionType.Ping)
finite gull

Probably not as discord.js should use 99% if not 100% of discord-api-types

EDIT: And if you're not using discord.js, probably not, as esbuild/eslint doesn't touch node_modules