Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More efficient JSON imports #2161

Closed
fabiospampinato opened this issue Apr 6, 2022 · 4 comments
Closed

More efficient JSON imports #2161

fabiospampinato opened this issue Apr 6, 2022 · 4 comments

Comments

@fabiospampinato
Copy link

fabiospampinato commented Apr 6, 2022

esbuild seems to transform json imports relatively inefficiently.

Given the following index.ts:

import db from './database.json';

const mime = db;

export default mime;

The following database.json:

{
  "application/andrew-inset": ["ez"],
  "application/applixware": ["aw"],
  "application/atom+xml": ["atom"],
  "application/atomcat+xml": ["atomcat"],
  "application/atomdeleted+xml": ["atomdeleted"],
  "application/atomsvc+xml": ["atomsvc"],
  "application/atsc-dwd+xml": ["dwd"],
  "application/atsc-held+xml": ["held"],
  "application/atsc-rsat+xml": ["rsat"],
  "application/bdoc": ["bdoc"],
  "application/calendar+xml": ["xcs"],
  "application/ccxml+xml": ["ccxml"],
  "application/cdfx+xml": ["cdfx"],
  "application/cdmi-capability": ["cdmia"],
  "application/cdmi-container": ["cdmic"],
  "application/cdmi-domain": ["cdmid"],
  "application/cdmi-object": ["cdmio"],
  "application/cdmi-queue": ["cdmiq"],
  "application/cu-seeme": ["cu"],
  "application/dash+xml": ["mpd"],
  "application/davmount+xml": ["davmount"],
  "application/docbook+xml": ["dbk"],
  "application/dssc+der": ["dssc"],
  "application/dssc+xml": ["xdssc"],
  "application/ecmascript": ["es", "ecma"],
  "application/emma+xml": ["emma"],
  "application/emotionml+xml": ["emotionml"],
  "application/epub+zip": ["epub"],
  "application/exi": ["exi"],
  "application/express": ["exp"],
  "application/fdt+xml": ["fdt"],
  "application/font-tdpfr": ["pfr"],
  "application/geo+json": ["geojson"],
  "application/gml+xml": ["gml"],
  "application/gpx+xml": ["gpx"],
  "application/gxf": ["gxf"],
  "application/gzip": ["gz"],
  "application/hjson": ["hjson"],
  "application/hyperstudio": ["stk"],
  "application/inkml+xml": ["ink", "inkml"],
  "application/ipfix": ["ipfix"],
  "application/its+xml": ["its"],
  "application/java-archive": ["jar", "war", "ear"],
  "application/java-serialized-object": ["ser"],
  "application/java-vm": ["class"],
  "application/javascript": ["js", "mjs"],
  "application/json": ["json", "map"],
  "application/json5": ["json5"],
  "application/jsonml+json": ["jsonml"],
  "application/ld+json": ["jsonld"],
  "application/lgr+xml": ["lgr"],
  "application/lost+xml": ["lostxml"],
  "application/mac-binhex40": ["hqx"],
  "application/mac-compactpro": ["cpt"],
  "application/mads+xml": ["mads"],
  "application/manifest+json": ["webmanifest"],
  "application/marc": ["mrc"],
  "application/marcxml+xml": ["mrcx"],
  "application/mathematica": ["ma", "nb", "mb"],
  "application/mathml+xml": ["mathml"],
  "application/mbox": ["mbox"],
  "application/mediaservercontrol+xml": ["mscml"],
  "application/metalink+xml": ["metalink"],
  "application/metalink4+xml": ["meta4"],
  "application/mets+xml": ["mets"],
  "application/mmt-aei+xml": ["maei"],
  "application/mmt-usd+xml": ["musd"],
  "application/mods+xml": ["mods"],
  "application/mp21": ["m21", "mp21"],
  "application/mp4": ["mp4s", "m4p"],
  "application/msword": ["doc", "dot"],
  "application/mxf": ["mxf"],
  "application/n-quads": ["nq"],
  "application/n-triples": ["nt"],
  "application/node": ["cjs"],
  "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"],
  "application/oda": ["oda"],
  "application/oebps-package+xml": ["opf"],
  "application/ogg": ["ogx"],
  "application/omdoc+xml": ["omdoc"],
  "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"],
  "application/oxps": ["oxps"],
  "application/p2p-overlay+xml": ["relo"],
  "application/patch-ops-error+xml": ["xer"],
  "application/pdf": ["pdf"],
  "application/pgp-encrypted": ["pgp"],
  "application/pgp-signature": ["asc", "sig"],
  "application/pics-rules": ["prf"],
  "application/pkcs10": ["p10"],
  "application/pkcs7-mime": ["p7m", "p7c"],
  "application/pkcs7-signature": ["p7s"],
  "application/pkcs8": ["p8"],
  "application/pkix-attr-cert": ["ac"],
  "application/pkix-cert": ["cer"],
  "application/pkix-crl": ["crl"],
  "application/pkix-pkipath": ["pkipath"],
  "application/pkixcmp": ["pki"],
  "application/pls+xml": ["pls"],
  "application/postscript": ["ai", "eps", "ps"],
  "application/provenance+xml": ["provx"],
  "application/pskc+xml": ["pskcxml"],
  "application/raml+yaml": ["raml"],
  "application/rdf+xml": ["rdf", "owl"],
  "application/reginfo+xml": ["rif"],
  "application/relax-ng-compact-syntax": ["rnc"],
  "application/resource-lists+xml": ["rl"],
  "application/resource-lists-diff+xml": ["rld"],
  "application/rls-services+xml": ["rs"],
  "application/route-apd+xml": ["rapd"],
  "application/route-s-tsid+xml": ["sls"],
  "application/route-usd+xml": ["rusd"],
  "application/rpki-ghostbusters": ["gbr"],
  "application/rpki-manifest": ["mft"],
  "application/rpki-roa": ["roa"],
  "application/rsd+xml": ["rsd"],
  "application/rss+xml": ["rss"],
  "application/rtf": ["rtf"],
  "application/sbml+xml": ["sbml"],
  "application/scvp-cv-request": ["scq"],
  "application/scvp-cv-response": ["scs"],
  "application/scvp-vp-request": ["spq"],
  "application/scvp-vp-response": ["spp"],
  "application/sdp": ["sdp"],
  "application/senml+xml": ["senmlx"],
  "application/sensml+xml": ["sensmlx"],
  "application/set-payment-initiation": ["setpay"],
  "application/set-registration-initiation": ["setreg"],
  "application/shf+xml": ["shf"],
  "application/sieve": ["siv", "sieve"],
  "application/smil+xml": ["smi", "smil"],
  "application/sparql-query": ["rq"],
  "application/sparql-results+xml": ["srx"],
  "application/srgs": ["gram"],
  "application/srgs+xml": ["grxml"],
  "application/sru+xml": ["sru"],
  "application/ssdl+xml": ["ssdl"],
  "application/ssml+xml": ["ssml"],
  "application/swid+xml": ["swidtag"],
  "application/tei+xml": ["tei", "teicorpus"],
  "application/thraud+xml": ["tfi"],
  "application/timestamped-data": ["tsd"],
  "application/toml": ["toml"],
  "application/trig": ["trig"],
  "application/ttml+xml": ["ttml"],
  "application/ubjson": ["ubj"],
  "application/urc-ressheet+xml": ["rsheet"],
  "application/urc-targetdesc+xml": ["td"],
  "application/voicexml+xml": ["vxml"],
  "application/wasm": ["wasm"],
  "application/widget": ["wgt"],
  "application/winhlp": ["hlp"],
  "application/wsdl+xml": ["wsdl"],
  "application/wspolicy+xml": ["wspolicy"],
  "application/xaml+xml": ["xaml"],
  "application/xcap-att+xml": ["xav"],
  "application/xcap-caps+xml": ["xca"],
  "application/xcap-diff+xml": ["xdf"],
  "application/xcap-el+xml": ["xel"],
  "application/xcap-ns+xml": ["xns"],
  "application/xenc+xml": ["xenc"],
  "application/xhtml+xml": ["xhtml", "xht"],
  "application/xliff+xml": ["xlf"],
  "application/xml": ["xml", "xsl", "xsd", "rng"],
  "application/xml-dtd": ["dtd"],
  "application/xop+xml": ["xop"],
  "application/xproc+xml": ["xpl"],
  "application/xslt+xml": ["*xsl", "xslt"],
  "application/xspf+xml": ["xspf"],
  "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"],
  "application/yang": ["yang"],
  "application/yin+xml": ["yin"],
  "application/zip": ["zip"],
  "audio/3gpp": ["*3gpp"],
  "audio/adpcm": ["adp"],
  "audio/amr": ["amr"],
  "audio/basic": ["au", "snd"],
  "audio/midi": ["mid", "midi", "kar", "rmi"],
  "audio/mobile-xmf": ["mxmf"],
  "audio/mp3": ["*mp3"],
  "audio/mp4": ["m4a", "mp4a"],
  "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"],
  "audio/ogg": ["oga", "ogg", "spx", "opus"],
  "audio/s3m": ["s3m"],
  "audio/silk": ["sil"],
  "audio/wav": ["wav"],
  "audio/wave": ["*wav"],
  "audio/webm": ["weba"],
  "audio/xm": ["xm"],
  "font/collection": ["ttc"],
  "font/otf": ["otf"],
  "font/ttf": ["ttf"],
  "font/woff": ["woff"],
  "font/woff2": ["woff2"],
  "image/aces": ["exr"],
  "image/apng": ["apng"],
  "image/avif": ["avif"],
  "image/bmp": ["bmp"],
  "image/cgm": ["cgm"],
  "image/dicom-rle": ["drle"],
  "image/emf": ["emf"],
  "image/fits": ["fits"],
  "image/g3fax": ["g3"],
  "image/gif": ["gif"],
  "image/heic": ["heic"],
  "image/heic-sequence": ["heics"],
  "image/heif": ["heif"],
  "image/heif-sequence": ["heifs"],
  "image/hej2k": ["hej2"],
  "image/hsj2": ["hsj2"],
  "image/ief": ["ief"],
  "image/jls": ["jls"],
  "image/jp2": ["jp2", "jpg2"],
  "image/jpeg": ["jpeg", "jpg", "jpe"],
  "image/jph": ["jph"],
  "image/jphc": ["jhc"],
  "image/jpm": ["jpm"],
  "image/jpx": ["jpx", "jpf"],
  "image/jxr": ["jxr"],
  "image/jxra": ["jxra"],
  "image/jxrs": ["jxrs"],
  "image/jxs": ["jxs"],
  "image/jxsc": ["jxsc"],
  "image/jxsi": ["jxsi"],
  "image/jxss": ["jxss"],
  "image/ktx": ["ktx"],
  "image/ktx2": ["ktx2"],
  "image/png": ["png"],
  "image/sgi": ["sgi"],
  "image/svg+xml": ["svg", "svgz"],
  "image/t38": ["t38"],
  "image/tiff": ["tif", "tiff"],
  "image/tiff-fx": ["tfx"],
  "image/webp": ["webp"],
  "image/wmf": ["wmf"],
  "message/disposition-notification": ["disposition-notification"],
  "message/global": ["u8msg"],
  "message/global-delivery-status": ["u8dsn"],
  "message/global-disposition-notification": ["u8mdn"],
  "message/global-headers": ["u8hdr"],
  "message/rfc822": ["eml", "mime"],
  "model/3mf": ["3mf"],
  "model/gltf+json": ["gltf"],
  "model/gltf-binary": ["glb"],
  "model/iges": ["igs", "iges"],
  "model/mesh": ["msh", "mesh", "silo"],
  "model/mtl": ["mtl"],
  "model/obj": ["obj"],
  "model/step+xml": ["stpx"],
  "model/step+zip": ["stpz"],
  "model/step-xml+zip": ["stpxz"],
  "model/stl": ["stl"],
  "model/vrml": ["wrl", "vrml"],
  "model/x3d+binary": ["*x3db", "x3dbz"],
  "model/x3d+fastinfoset": ["x3db"],
  "model/x3d+vrml": ["*x3dv", "x3dvz"],
  "model/x3d+xml": ["x3d", "x3dz"],
  "model/x3d-vrml": ["x3dv"],
  "text/cache-manifest": ["appcache", "manifest"],
  "text/calendar": ["ics", "ifb"],
  "text/coffeescript": ["coffee", "litcoffee"],
  "text/css": ["css"],
  "text/csv": ["csv"],
  "text/html": ["html", "htm", "shtml"],
  "text/jade": ["jade"],
  "text/jsx": ["jsx"],
  "text/less": ["less"],
  "text/markdown": ["markdown", "md"],
  "text/mathml": ["mml"],
  "text/mdx": ["mdx"],
  "text/n3": ["n3"],
  "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"],
  "text/richtext": ["rtx"],
  "text/rtf": ["*rtf"],
  "text/sgml": ["sgml", "sgm"],
  "text/shex": ["shex"],
  "text/slim": ["slim", "slm"],
  "text/spdx": ["spdx"],
  "text/stylus": ["stylus", "styl"],
  "text/tab-separated-values": ["tsv"],
  "text/troff": ["t", "tr", "roff", "man", "me", "ms"],
  "text/turtle": ["ttl"],
  "text/uri-list": ["uri", "uris", "urls"],
  "text/vcard": ["vcard"],
  "text/vtt": ["vtt"],
  "text/xml": ["*xml"],
  "text/yaml": ["yaml", "yml"],
  "video/3gpp": ["3gp", "3gpp"],
  "video/3gpp2": ["3g2"],
  "video/h261": ["h261"],
  "video/h263": ["h263"],
  "video/h264": ["h264"],
  "video/iso.segment": ["m4s"],
  "video/jpeg": ["jpgv"],
  "video/jpm": ["*jpm", "jpgm"],
  "video/mj2": ["mj2", "mjp2"],
  "video/mp2t": ["ts"],
  "video/mp4": ["mp4", "mp4v", "mpg4"],
  "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"],
  "video/ogg": ["ogv"],
  "video/quicktime": ["qt", "mov"],
  "video/webm": ["webm"]
}

And the following command:

esbuild --bundle ./index.ts --minify

I'm getting the following code, beautified by me to highlight the problem:

(() => {
  var p = ["ez"],
    t = ["aw"],
    l = ["atom"],
    m = ["atomcat"],
    o = ["atomdeleted"],
    e = ["atomsvc"],
    c = ["dwd"],
    s = ["held"],
    n = ["rsat"],
    x = ["bdoc"],
    d = ["xcs"],
    r = ["ccxml"],
    g = ["cdfx"],
    f = ["cdmia"],
    v = ["cdmic"],
    j = ["cdmid"],
    u = ["cdmio"],
    h = ["cdmiq"],
    b = ["cu"],
    k = ["mpd"],
    w = ["davmount"],
    y = ["dbk"],
    q = ["dssc"],
    z = ["xdssc"],
    A = ["es", "ecma"],
    B = ["emma"],
    C = ["emotionml"],
    D = ["epub"],
    E = ["exi"],
    F = ["exp"],
    G = ["fdt"],
    H = ["pfr"],
    I = ["geojson"],
    J = ["gml"],
    K = ["gpx"],
    L = ["gxf"],
    M = ["gz"],
    N = ["hjson"],
    O = ["stk"],
    P = ["ink", "inkml"],
    Q = ["ipfix"],
    R = ["its"],
    S = ["jar", "war", "ear"],
    T = ["ser"],
    U = ["class"],
    V = ["js", "mjs"],
    W = ["json", "map"],
    X = ["json5"],
    Y = ["jsonml"],
    Z = ["jsonld"],
    _ = ["lgr"],
    $ = ["lostxml"],
    ii = ["hqx"],
    ai = ["cpt"],
    pi = ["mads"],
    ti = ["webmanifest"],
    li = ["mrc"],
    mi = ["mrcx"],
    oi = ["ma", "nb", "mb"],
    ei = ["mathml"],
    ci = ["mbox"],
    si = ["mscml"],
    ni = ["metalink"],
    xi = ["meta4"],
    di = ["mets"],
    ri = ["maei"],
    gi = ["musd"],
    fi = ["mods"],
    vi = ["m21", "mp21"],
    ji = ["mp4s", "m4p"],
    ui = ["doc", "dot"],
    hi = ["mxf"],
    bi = ["nq"],
    ki = ["nt"],
    wi = ["cjs"],
    yi = ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"],
    qi = ["oda"],
    zi = ["opf"],
    Ai = ["ogx"],
    Bi = ["omdoc"],
    Ci = ["onetoc", "onetoc2", "onetmp", "onepkg"],
    Di = ["oxps"],
    Ei = ["relo"],
    Fi = ["xer"],
    Gi = ["pdf"],
    Hi = ["pgp"],
    Ii = ["asc", "sig"],
    Ji = ["prf"],
    Ki = ["p10"],
    Li = ["p7m", "p7c"],
    Mi = ["p7s"],
    Ni = ["p8"],
    Oi = ["ac"],
    Pi = ["cer"],
    Qi = ["crl"],
    Ri = ["pkipath"],
    Si = ["pki"],
    Ti = ["pls"],
    Ui = ["ai", "eps", "ps"],
    Vi = ["provx"],
    Wi = ["pskcxml"],
    Xi = ["raml"],
    Yi = ["rdf", "owl"],
    Zi = ["rif"],
    _i = ["rnc"],
    $i = ["rl"],
    ia = ["rld"],
    aa = ["rs"],
    pa = ["rapd"],
    ta = ["sls"],
    la = ["rusd"],
    ma = ["gbr"],
    oa = ["mft"],
    ea = ["roa"],
    ca = ["rsd"],
    sa = ["rss"],
    na = ["rtf"],
    xa = ["sbml"],
    da = ["scq"],
    ra = ["scs"],
    ga = ["spq"],
    fa = ["spp"],
    va = ["sdp"],
    ja = ["senmlx"],
    ua = ["sensmlx"],
    ha = ["setpay"],
    ba = ["setreg"],
    ka = ["shf"],
    wa = ["siv", "sieve"],
    ya = ["smi", "smil"],
    qa = ["rq"],
    za = ["srx"],
    Aa = ["gram"],
    Ba = ["grxml"],
    Ca = ["sru"],
    Da = ["ssdl"],
    Ea = ["ssml"],
    Fa = ["swidtag"],
    Ga = ["tei", "teicorpus"],
    Ha = ["tfi"],
    Ia = ["tsd"],
    Ja = ["toml"],
    Ka = ["trig"],
    La = ["ttml"],
    Ma = ["ubj"],
    Na = ["rsheet"],
    Oa = ["td"],
    Pa = ["vxml"],
    Qa = ["wasm"],
    Ra = ["wgt"],
    Sa = ["hlp"],
    Ta = ["wsdl"],
    Ua = ["wspolicy"],
    Va = ["xaml"],
    Wa = ["xav"],
    Xa = ["xca"],
    Ya = ["xdf"],
    Za = ["xel"],
    _a = ["xns"],
    $a = ["xenc"],
    ip = ["xhtml", "xht"],
    ap = ["xlf"],
    pp = ["xml", "xsl", "xsd", "rng"],
    tp = ["dtd"],
    lp = ["xop"],
    mp = ["xpl"],
    op = ["*xsl", "xslt"],
    ep = ["xspf"],
    cp = ["mxml", "xhvml", "xvml", "xvm"],
    sp = ["yang"],
    np = ["yin"],
    xp = ["zip"],
    dp = ["*3gpp"],
    rp = ["adp"],
    gp = ["amr"],
    fp = ["au", "snd"],
    vp = ["mid", "midi", "kar", "rmi"],
    jp = ["mxmf"],
    up = ["*mp3"],
    hp = ["m4a", "mp4a"],
    bp = ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"],
    kp = ["oga", "ogg", "spx", "opus"],
    wp = ["s3m"],
    yp = ["sil"],
    qp = ["wav"],
    zp = ["*wav"],
    Ap = ["weba"],
    Bp = ["xm"],
    Cp = ["ttc"],
    Dp = ["otf"],
    Ep = ["ttf"],
    Fp = ["woff"],
    Gp = ["woff2"],
    Hp = ["exr"],
    Ip = ["apng"],
    Jp = ["avif"],
    Kp = ["bmp"],
    Lp = ["cgm"],
    Mp = ["drle"],
    Np = ["emf"],
    Op = ["fits"],
    Pp = ["g3"],
    Qp = ["gif"],
    Rp = ["heic"],
    Sp = ["heics"],
    Tp = ["heif"],
    Up = ["heifs"],
    Vp = ["hej2"],
    Wp = ["hsj2"],
    Xp = ["ief"],
    Yp = ["jls"],
    Zp = ["jp2", "jpg2"],
    _p = ["jpeg", "jpg", "jpe"],
    $p = ["jph"],
    it = ["jhc"],
    at = ["jpm"],
    pt = ["jpx", "jpf"],
    tt = ["jxr"],
    lt = ["jxra"],
    mt = ["jxrs"],
    ot = ["jxs"],
    et = ["jxsc"],
    ct = ["jxsi"],
    st = ["jxss"],
    nt = ["ktx"],
    xt = ["ktx2"],
    dt = ["png"],
    rt = ["sgi"],
    gt = ["svg", "svgz"],
    ft = ["t38"],
    vt = ["tif", "tiff"],
    jt = ["tfx"],
    ut = ["webp"],
    ht = ["wmf"],
    bt = ["disposition-notification"],
    kt = ["u8msg"],
    wt = ["u8dsn"],
    yt = ["u8mdn"],
    qt = ["u8hdr"],
    zt = ["eml", "mime"],
    At = ["3mf"],
    Bt = ["gltf"],
    Ct = ["glb"],
    Dt = ["igs", "iges"],
    Et = ["msh", "mesh", "silo"],
    Ft = ["mtl"],
    Gt = ["obj"],
    Ht = ["stpx"],
    It = ["stpz"],
    Jt = ["stpxz"],
    Kt = ["stl"],
    Lt = ["wrl", "vrml"],
    Mt = ["*x3db", "x3dbz"],
    Nt = ["x3db"],
    Ot = ["*x3dv", "x3dvz"],
    Pt = ["x3d", "x3dz"],
    Qt = ["x3dv"],
    Rt = ["appcache", "manifest"],
    St = ["ics", "ifb"],
    Tt = ["coffee", "litcoffee"],
    Ut = ["css"],
    Vt = ["csv"],
    Wt = ["html", "htm", "shtml"],
    Xt = ["jade"],
    Yt = ["jsx"],
    Zt = ["less"],
    _t = ["markdown", "md"],
    $t = ["mml"],
    il = ["mdx"],
    al = ["n3"],
    pl = ["txt", "text", "conf", "def", "list", "log", "in", "ini"],
    tl = ["rtx"],
    ll = ["*rtf"],
    ml = ["sgml", "sgm"],
    ol = ["shex"],
    el = ["slim", "slm"],
    cl = ["spdx"],
    sl = ["stylus", "styl"],
    nl = ["tsv"],
    xl = ["t", "tr", "roff", "man", "me", "ms"],
    dl = ["ttl"],
    rl = ["uri", "uris", "urls"],
    gl = ["vcard"],
    fl = ["vtt"],
    vl = ["*xml"],
    jl = ["yaml", "yml"],
    ul = ["3gp", "3gpp"],
    hl = ["3g2"],
    bl = ["h261"],
    kl = ["h263"],
    wl = ["h264"],
    yl = ["m4s"],
    ql = ["jpgv"],
    zl = ["*jpm", "jpgm"],
    Al = ["mj2", "mjp2"],
    Bl = ["ts"],
    Cl = ["mp4", "mp4v", "mpg4"],
    Dl = ["mpeg", "mpg", "mpe", "m1v", "m2v"],
    El = ["ogv"],
    Fl = ["qt", "mov"],
    Gl = ["webm"],
    a = {
      "application/andrew-inset": p,
      "application/applixware": t,
      "application/atom+xml": l,
      "application/atomcat+xml": m,
      "application/atomdeleted+xml": o,
      "application/atomsvc+xml": e,
      "application/atsc-dwd+xml": c,
      "application/atsc-held+xml": s,
      "application/atsc-rsat+xml": n,
      "application/bdoc": x,
      "application/calendar+xml": d,
      "application/ccxml+xml": r,
      "application/cdfx+xml": g,
      "application/cdmi-capability": f,
      "application/cdmi-container": v,
      "application/cdmi-domain": j,
      "application/cdmi-object": u,
      "application/cdmi-queue": h,
      "application/cu-seeme": b,
      "application/dash+xml": k,
      "application/davmount+xml": w,
      "application/docbook+xml": y,
      "application/dssc+der": q,
      "application/dssc+xml": z,
      "application/ecmascript": A,
      "application/emma+xml": B,
      "application/emotionml+xml": C,
      "application/epub+zip": D,
      "application/exi": E,
      "application/express": F,
      "application/fdt+xml": G,
      "application/font-tdpfr": H,
      "application/geo+json": I,
      "application/gml+xml": J,
      "application/gpx+xml": K,
      "application/gxf": L,
      "application/gzip": M,
      "application/hjson": N,
      "application/hyperstudio": O,
      "application/inkml+xml": P,
      "application/ipfix": Q,
      "application/its+xml": R,
      "application/java-archive": S,
      "application/java-serialized-object": T,
      "application/java-vm": U,
      "application/javascript": V,
      "application/json": W,
      "application/json5": X,
      "application/jsonml+json": Y,
      "application/ld+json": Z,
      "application/lgr+xml": _,
      "application/lost+xml": $,
      "application/mac-binhex40": ii,
      "application/mac-compactpro": ai,
      "application/mads+xml": pi,
      "application/manifest+json": ti,
      "application/marc": li,
      "application/marcxml+xml": mi,
      "application/mathematica": oi,
      "application/mathml+xml": ei,
      "application/mbox": ci,
      "application/mediaservercontrol+xml": si,
      "application/metalink+xml": ni,
      "application/metalink4+xml": xi,
      "application/mets+xml": di,
      "application/mmt-aei+xml": ri,
      "application/mmt-usd+xml": gi,
      "application/mods+xml": fi,
      "application/mp21": vi,
      "application/mp4": ji,
      "application/msword": ui,
      "application/mxf": hi,
      "application/n-quads": bi,
      "application/n-triples": ki,
      "application/node": wi,
      "application/octet-stream": yi,
      "application/oda": qi,
      "application/oebps-package+xml": zi,
      "application/ogg": Ai,
      "application/omdoc+xml": Bi,
      "application/onenote": Ci,
      "application/oxps": Di,
      "application/p2p-overlay+xml": Ei,
      "application/patch-ops-error+xml": Fi,
      "application/pdf": Gi,
      "application/pgp-encrypted": Hi,
      "application/pgp-signature": Ii,
      "application/pics-rules": Ji,
      "application/pkcs10": Ki,
      "application/pkcs7-mime": Li,
      "application/pkcs7-signature": Mi,
      "application/pkcs8": Ni,
      "application/pkix-attr-cert": Oi,
      "application/pkix-cert": Pi,
      "application/pkix-crl": Qi,
      "application/pkix-pkipath": Ri,
      "application/pkixcmp": Si,
      "application/pls+xml": Ti,
      "application/postscript": Ui,
      "application/provenance+xml": Vi,
      "application/pskc+xml": Wi,
      "application/raml+yaml": Xi,
      "application/rdf+xml": Yi,
      "application/reginfo+xml": Zi,
      "application/relax-ng-compact-syntax": _i,
      "application/resource-lists+xml": $i,
      "application/resource-lists-diff+xml": ia,
      "application/rls-services+xml": aa,
      "application/route-apd+xml": pa,
      "application/route-s-tsid+xml": ta,
      "application/route-usd+xml": la,
      "application/rpki-ghostbusters": ma,
      "application/rpki-manifest": oa,
      "application/rpki-roa": ea,
      "application/rsd+xml": ca,
      "application/rss+xml": sa,
      "application/rtf": na,
      "application/sbml+xml": xa,
      "application/scvp-cv-request": da,
      "application/scvp-cv-response": ra,
      "application/scvp-vp-request": ga,
      "application/scvp-vp-response": fa,
      "application/sdp": va,
      "application/senml+xml": ja,
      "application/sensml+xml": ua,
      "application/set-payment-initiation": ha,
      "application/set-registration-initiation": ba,
      "application/shf+xml": ka,
      "application/sieve": wa,
      "application/smil+xml": ya,
      "application/sparql-query": qa,
      "application/sparql-results+xml": za,
      "application/srgs": Aa,
      "application/srgs+xml": Ba,
      "application/sru+xml": Ca,
      "application/ssdl+xml": Da,
      "application/ssml+xml": Ea,
      "application/swid+xml": Fa,
      "application/tei+xml": Ga,
      "application/thraud+xml": Ha,
      "application/timestamped-data": Ia,
      "application/toml": Ja,
      "application/trig": Ka,
      "application/ttml+xml": La,
      "application/ubjson": Ma,
      "application/urc-ressheet+xml": Na,
      "application/urc-targetdesc+xml": Oa,
      "application/voicexml+xml": Pa,
      "application/wasm": Qa,
      "application/widget": Ra,
      "application/winhlp": Sa,
      "application/wsdl+xml": Ta,
      "application/wspolicy+xml": Ua,
      "application/xaml+xml": Va,
      "application/xcap-att+xml": Wa,
      "application/xcap-caps+xml": Xa,
      "application/xcap-diff+xml": Ya,
      "application/xcap-el+xml": Za,
      "application/xcap-ns+xml": _a,
      "application/xenc+xml": $a,
      "application/xhtml+xml": ip,
      "application/xliff+xml": ap,
      "application/xml": pp,
      "application/xml-dtd": tp,
      "application/xop+xml": lp,
      "application/xproc+xml": mp,
      "application/xslt+xml": op,
      "application/xspf+xml": ep,
      "application/xv+xml": cp,
      "application/yang": sp,
      "application/yin+xml": np,
      "application/zip": xp,
      "audio/3gpp": dp,
      "audio/adpcm": rp,
      "audio/amr": gp,
      "audio/basic": fp,
      "audio/midi": vp,
      "audio/mobile-xmf": jp,
      "audio/mp3": up,
      "audio/mp4": hp,
      "audio/mpeg": bp,
      "audio/ogg": kp,
      "audio/s3m": wp,
      "audio/silk": yp,
      "audio/wav": qp,
      "audio/wave": zp,
      "audio/webm": Ap,
      "audio/xm": Bp,
      "font/collection": Cp,
      "font/otf": Dp,
      "font/ttf": Ep,
      "font/woff": Fp,
      "font/woff2": Gp,
      "image/aces": Hp,
      "image/apng": Ip,
      "image/avif": Jp,
      "image/bmp": Kp,
      "image/cgm": Lp,
      "image/dicom-rle": Mp,
      "image/emf": Np,
      "image/fits": Op,
      "image/g3fax": Pp,
      "image/gif": Qp,
      "image/heic": Rp,
      "image/heic-sequence": Sp,
      "image/heif": Tp,
      "image/heif-sequence": Up,
      "image/hej2k": Vp,
      "image/hsj2": Wp,
      "image/ief": Xp,
      "image/jls": Yp,
      "image/jp2": Zp,
      "image/jpeg": _p,
      "image/jph": $p,
      "image/jphc": it,
      "image/jpm": at,
      "image/jpx": pt,
      "image/jxr": tt,
      "image/jxra": lt,
      "image/jxrs": mt,
      "image/jxs": ot,
      "image/jxsc": et,
      "image/jxsi": ct,
      "image/jxss": st,
      "image/ktx": nt,
      "image/ktx2": xt,
      "image/png": dt,
      "image/sgi": rt,
      "image/svg+xml": gt,
      "image/t38": ft,
      "image/tiff": vt,
      "image/tiff-fx": jt,
      "image/webp": ut,
      "image/wmf": ht,
      "message/disposition-notification": bt,
      "message/global": kt,
      "message/global-delivery-status": wt,
      "message/global-disposition-notification": yt,
      "message/global-headers": qt,
      "message/rfc822": zt,
      "model/3mf": At,
      "model/gltf+json": Bt,
      "model/gltf-binary": Ct,
      "model/iges": Dt,
      "model/mesh": Et,
      "model/mtl": Ft,
      "model/obj": Gt,
      "model/step+xml": Ht,
      "model/step+zip": It,
      "model/step-xml+zip": Jt,
      "model/stl": Kt,
      "model/vrml": Lt,
      "model/x3d+binary": Mt,
      "model/x3d+fastinfoset": Nt,
      "model/x3d+vrml": Ot,
      "model/x3d+xml": Pt,
      "model/x3d-vrml": Qt,
      "text/cache-manifest": Rt,
      "text/calendar": St,
      "text/coffeescript": Tt,
      "text/css": Ut,
      "text/csv": Vt,
      "text/html": Wt,
      "text/jade": Xt,
      "text/jsx": Yt,
      "text/less": Zt,
      "text/markdown": _t,
      "text/mathml": $t,
      "text/mdx": il,
      "text/n3": al,
      "text/plain": pl,
      "text/richtext": tl,
      "text/rtf": ll,
      "text/sgml": ml,
      "text/shex": ol,
      "text/slim": el,
      "text/spdx": cl,
      "text/stylus": sl,
      "text/tab-separated-values": nl,
      "text/troff": xl,
      "text/turtle": dl,
      "text/uri-list": rl,
      "text/vcard": gl,
      "text/vtt": fl,
      "text/xml": vl,
      "text/yaml": jl,
      "video/3gpp": ul,
      "video/3gpp2": hl,
      "video/h261": bl,
      "video/h263": kl,
      "video/h264": wl,
      "video/iso.segment": yl,
      "video/jpeg": ql,
      "video/jpm": zl,
      "video/mj2": Al,
      "video/mp2t": Bl,
      "video/mp4": Cl,
      "video/mpeg": Dl,
      "video/ogg": El,
      "video/quicktime": Fl,
      "video/webm": Gl
    };
  var Hl = a,
    Kl = Hl;
})();

There's basically a huge number of unnecessary intermediate variables, I would have expected to find the input json basically copy/pasted in the output file, but that wasn't the case.

@hyrious
Copy link

hyrious commented Apr 7, 2022

This is because the default json loader (built-in in esbuild) turns a json file into this form:

// { "a": [42] }
export var a = [42]
export default { a }

// this guarantees that
import X, { a } from "./a.json"
X.a === a // true, is same thing (by reference)

But key names are repeated at least 2 times. In that case, you can write a plugin to alter that behavior if you only want the default export:

var MyJsonLoader = {
  name: 'my-json-loader',
  setup({ onLoad }) {
    onLoad({ filter: /\.json$/ }, async args => {
      const text = await fs.promises.readFile(args.path, 'utf8')
      return { contents: `export default ${text}` }
    })
  }
}

(I don't think this behavior should be built-in, since it requires some analysis around the usage of a json file (whether it was imported by names).

@fabiospampinato
Copy link
Author

fabiospampinato commented Apr 7, 2022

(I don't think this behavior should be built-in, since it requires some analysis around the usage of a json file (whether it was imported by names).

Wouldn't this be a trivial check though? It seems worth it to me, the length of the output code can get a little out of hand otherwise.

@evanw
Copy link
Owner

evanw commented Apr 7, 2022

The reason for this is tree-shaking. For example, the following code:

export { 'application/wasm' as wasm } from './database.json'

currently bundles into the following code (with --bundle --format=esm):

// database.json
var application_wasm = ["wasm"];
export {
  application_wasm as wasm
};

With your suggested change, you would have to do something like this instead:

import db from './database.js'
export let { 'application/wasm': wasm } = db

which would bundle into the following code (with --bundle --format=esm):

// database.json
var database_default = {
  "application/andrew-inset": ["ez"],
  "application/applixware": ["aw"],
  "application/atom+xml": ["atom"],
  "application/atomcat+xml": ["atomcat"],
  "application/atomdeleted+xml": ["atomdeleted"],
  "application/atomsvc+xml": ["atomsvc"],
  "application/atsc-dwd+xml": ["dwd"],
  "application/atsc-held+xml": ["held"],
  "application/atsc-rsat+xml": ["rsat"],
  "application/bdoc": ["bdoc"],
  "application/calendar+xml": ["xcs"],
  "application/ccxml+xml": ["ccxml"],
  "application/cdfx+xml": ["cdfx"],
  "application/cdmi-capability": ["cdmia"],
  "application/cdmi-container": ["cdmic"],
  "application/cdmi-domain": ["cdmid"],
  "application/cdmi-object": ["cdmio"],
  "application/cdmi-queue": ["cdmiq"],
  "application/cu-seeme": ["cu"],
  "application/dash+xml": ["mpd"],
  "application/davmount+xml": ["davmount"],
  "application/docbook+xml": ["dbk"],
  "application/dssc+der": ["dssc"],
  "application/dssc+xml": ["xdssc"],
  "application/ecmascript": ["es", "ecma"],
  "application/emma+xml": ["emma"],
  "application/emotionml+xml": ["emotionml"],
  "application/epub+zip": ["epub"],
  "application/exi": ["exi"],
  "application/express": ["exp"],
  "application/fdt+xml": ["fdt"],
  "application/font-tdpfr": ["pfr"],
  "application/geo+json": ["geojson"],
  "application/gml+xml": ["gml"],
  "application/gpx+xml": ["gpx"],
  "application/gxf": ["gxf"],
  "application/gzip": ["gz"],
  "application/hjson": ["hjson"],
  "application/hyperstudio": ["stk"],
  "application/inkml+xml": ["ink", "inkml"],
  "application/ipfix": ["ipfix"],
  "application/its+xml": ["its"],
  "application/java-archive": ["jar", "war", "ear"],
  "application/java-serialized-object": ["ser"],
  "application/java-vm": ["class"],
  "application/javascript": ["js", "mjs"],
  "application/json": ["json", "map"],
  "application/json5": ["json5"],
  "application/jsonml+json": ["jsonml"],
  "application/ld+json": ["jsonld"],
  "application/lgr+xml": ["lgr"],
  "application/lost+xml": ["lostxml"],
  "application/mac-binhex40": ["hqx"],
  "application/mac-compactpro": ["cpt"],
  "application/mads+xml": ["mads"],
  "application/manifest+json": ["webmanifest"],
  "application/marc": ["mrc"],
  "application/marcxml+xml": ["mrcx"],
  "application/mathematica": ["ma", "nb", "mb"],
  "application/mathml+xml": ["mathml"],
  "application/mbox": ["mbox"],
  "application/mediaservercontrol+xml": ["mscml"],
  "application/metalink+xml": ["metalink"],
  "application/metalink4+xml": ["meta4"],
  "application/mets+xml": ["mets"],
  "application/mmt-aei+xml": ["maei"],
  "application/mmt-usd+xml": ["musd"],
  "application/mods+xml": ["mods"],
  "application/mp21": ["m21", "mp21"],
  "application/mp4": ["mp4s", "m4p"],
  "application/msword": ["doc", "dot"],
  "application/mxf": ["mxf"],
  "application/n-quads": ["nq"],
  "application/n-triples": ["nt"],
  "application/node": ["cjs"],
  "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"],
  "application/oda": ["oda"],
  "application/oebps-package+xml": ["opf"],
  "application/ogg": ["ogx"],
  "application/omdoc+xml": ["omdoc"],
  "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"],
  "application/oxps": ["oxps"],
  "application/p2p-overlay+xml": ["relo"],
  "application/patch-ops-error+xml": ["xer"],
  "application/pdf": ["pdf"],
  "application/pgp-encrypted": ["pgp"],
  "application/pgp-signature": ["asc", "sig"],
  "application/pics-rules": ["prf"],
  "application/pkcs10": ["p10"],
  "application/pkcs7-mime": ["p7m", "p7c"],
  "application/pkcs7-signature": ["p7s"],
  "application/pkcs8": ["p8"],
  "application/pkix-attr-cert": ["ac"],
  "application/pkix-cert": ["cer"],
  "application/pkix-crl": ["crl"],
  "application/pkix-pkipath": ["pkipath"],
  "application/pkixcmp": ["pki"],
  "application/pls+xml": ["pls"],
  "application/postscript": ["ai", "eps", "ps"],
  "application/provenance+xml": ["provx"],
  "application/pskc+xml": ["pskcxml"],
  "application/raml+yaml": ["raml"],
  "application/rdf+xml": ["rdf", "owl"],
  "application/reginfo+xml": ["rif"],
  "application/relax-ng-compact-syntax": ["rnc"],
  "application/resource-lists+xml": ["rl"],
  "application/resource-lists-diff+xml": ["rld"],
  "application/rls-services+xml": ["rs"],
  "application/route-apd+xml": ["rapd"],
  "application/route-s-tsid+xml": ["sls"],
  "application/route-usd+xml": ["rusd"],
  "application/rpki-ghostbusters": ["gbr"],
  "application/rpki-manifest": ["mft"],
  "application/rpki-roa": ["roa"],
  "application/rsd+xml": ["rsd"],
  "application/rss+xml": ["rss"],
  "application/rtf": ["rtf"],
  "application/sbml+xml": ["sbml"],
  "application/scvp-cv-request": ["scq"],
  "application/scvp-cv-response": ["scs"],
  "application/scvp-vp-request": ["spq"],
  "application/scvp-vp-response": ["spp"],
  "application/sdp": ["sdp"],
  "application/senml+xml": ["senmlx"],
  "application/sensml+xml": ["sensmlx"],
  "application/set-payment-initiation": ["setpay"],
  "application/set-registration-initiation": ["setreg"],
  "application/shf+xml": ["shf"],
  "application/sieve": ["siv", "sieve"],
  "application/smil+xml": ["smi", "smil"],
  "application/sparql-query": ["rq"],
  "application/sparql-results+xml": ["srx"],
  "application/srgs": ["gram"],
  "application/srgs+xml": ["grxml"],
  "application/sru+xml": ["sru"],
  "application/ssdl+xml": ["ssdl"],
  "application/ssml+xml": ["ssml"],
  "application/swid+xml": ["swidtag"],
  "application/tei+xml": ["tei", "teicorpus"],
  "application/thraud+xml": ["tfi"],
  "application/timestamped-data": ["tsd"],
  "application/toml": ["toml"],
  "application/trig": ["trig"],
  "application/ttml+xml": ["ttml"],
  "application/ubjson": ["ubj"],
  "application/urc-ressheet+xml": ["rsheet"],
  "application/urc-targetdesc+xml": ["td"],
  "application/voicexml+xml": ["vxml"],
  "application/wasm": ["wasm"],
  "application/widget": ["wgt"],
  "application/winhlp": ["hlp"],
  "application/wsdl+xml": ["wsdl"],
  "application/wspolicy+xml": ["wspolicy"],
  "application/xaml+xml": ["xaml"],
  "application/xcap-att+xml": ["xav"],
  "application/xcap-caps+xml": ["xca"],
  "application/xcap-diff+xml": ["xdf"],
  "application/xcap-el+xml": ["xel"],
  "application/xcap-ns+xml": ["xns"],
  "application/xenc+xml": ["xenc"],
  "application/xhtml+xml": ["xhtml", "xht"],
  "application/xliff+xml": ["xlf"],
  "application/xml": ["xml", "xsl", "xsd", "rng"],
  "application/xml-dtd": ["dtd"],
  "application/xop+xml": ["xop"],
  "application/xproc+xml": ["xpl"],
  "application/xslt+xml": ["*xsl", "xslt"],
  "application/xspf+xml": ["xspf"],
  "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"],
  "application/yang": ["yang"],
  "application/yin+xml": ["yin"],
  "application/zip": ["zip"],
  "audio/3gpp": ["*3gpp"],
  "audio/adpcm": ["adp"],
  "audio/amr": ["amr"],
  "audio/basic": ["au", "snd"],
  "audio/midi": ["mid", "midi", "kar", "rmi"],
  "audio/mobile-xmf": ["mxmf"],
  "audio/mp3": ["*mp3"],
  "audio/mp4": ["m4a", "mp4a"],
  "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"],
  "audio/ogg": ["oga", "ogg", "spx", "opus"],
  "audio/s3m": ["s3m"],
  "audio/silk": ["sil"],
  "audio/wav": ["wav"],
  "audio/wave": ["*wav"],
  "audio/webm": ["weba"],
  "audio/xm": ["xm"],
  "font/collection": ["ttc"],
  "font/otf": ["otf"],
  "font/ttf": ["ttf"],
  "font/woff": ["woff"],
  "font/woff2": ["woff2"],
  "image/aces": ["exr"],
  "image/apng": ["apng"],
  "image/avif": ["avif"],
  "image/bmp": ["bmp"],
  "image/cgm": ["cgm"],
  "image/dicom-rle": ["drle"],
  "image/emf": ["emf"],
  "image/fits": ["fits"],
  "image/g3fax": ["g3"],
  "image/gif": ["gif"],
  "image/heic": ["heic"],
  "image/heic-sequence": ["heics"],
  "image/heif": ["heif"],
  "image/heif-sequence": ["heifs"],
  "image/hej2k": ["hej2"],
  "image/hsj2": ["hsj2"],
  "image/ief": ["ief"],
  "image/jls": ["jls"],
  "image/jp2": ["jp2", "jpg2"],
  "image/jpeg": ["jpeg", "jpg", "jpe"],
  "image/jph": ["jph"],
  "image/jphc": ["jhc"],
  "image/jpm": ["jpm"],
  "image/jpx": ["jpx", "jpf"],
  "image/jxr": ["jxr"],
  "image/jxra": ["jxra"],
  "image/jxrs": ["jxrs"],
  "image/jxs": ["jxs"],
  "image/jxsc": ["jxsc"],
  "image/jxsi": ["jxsi"],
  "image/jxss": ["jxss"],
  "image/ktx": ["ktx"],
  "image/ktx2": ["ktx2"],
  "image/png": ["png"],
  "image/sgi": ["sgi"],
  "image/svg+xml": ["svg", "svgz"],
  "image/t38": ["t38"],
  "image/tiff": ["tif", "tiff"],
  "image/tiff-fx": ["tfx"],
  "image/webp": ["webp"],
  "image/wmf": ["wmf"],
  "message/disposition-notification": ["disposition-notification"],
  "message/global": ["u8msg"],
  "message/global-delivery-status": ["u8dsn"],
  "message/global-disposition-notification": ["u8mdn"],
  "message/global-headers": ["u8hdr"],
  "message/rfc822": ["eml", "mime"],
  "model/3mf": ["3mf"],
  "model/gltf+json": ["gltf"],
  "model/gltf-binary": ["glb"],
  "model/iges": ["igs", "iges"],
  "model/mesh": ["msh", "mesh", "silo"],
  "model/mtl": ["mtl"],
  "model/obj": ["obj"],
  "model/step+xml": ["stpx"],
  "model/step+zip": ["stpz"],
  "model/step-xml+zip": ["stpxz"],
  "model/stl": ["stl"],
  "model/vrml": ["wrl", "vrml"],
  "model/x3d+binary": ["*x3db", "x3dbz"],
  "model/x3d+fastinfoset": ["x3db"],
  "model/x3d+vrml": ["*x3dv", "x3dvz"],
  "model/x3d+xml": ["x3d", "x3dz"],
  "model/x3d-vrml": ["x3dv"],
  "text/cache-manifest": ["appcache", "manifest"],
  "text/calendar": ["ics", "ifb"],
  "text/coffeescript": ["coffee", "litcoffee"],
  "text/css": ["css"],
  "text/csv": ["csv"],
  "text/html": ["html", "htm", "shtml"],
  "text/jade": ["jade"],
  "text/jsx": ["jsx"],
  "text/less": ["less"],
  "text/markdown": ["markdown", "md"],
  "text/mathml": ["mml"],
  "text/mdx": ["mdx"],
  "text/n3": ["n3"],
  "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"],
  "text/richtext": ["rtx"],
  "text/rtf": ["*rtf"],
  "text/sgml": ["sgml", "sgm"],
  "text/shex": ["shex"],
  "text/slim": ["slim", "slm"],
  "text/spdx": ["spdx"],
  "text/stylus": ["stylus", "styl"],
  "text/tab-separated-values": ["tsv"],
  "text/troff": ["t", "tr", "roff", "man", "me", "ms"],
  "text/turtle": ["ttl"],
  "text/uri-list": ["uri", "uris", "urls"],
  "text/vcard": ["vcard"],
  "text/vtt": ["vtt"],
  "text/xml": ["*xml"],
  "text/yaml": ["yaml", "yml"],
  "video/3gpp": ["3gp", "3gpp"],
  "video/3gpp2": ["3g2"],
  "video/h261": ["h261"],
  "video/h263": ["h263"],
  "video/h264": ["h264"],
  "video/iso.segment": ["m4s"],
  "video/jpeg": ["jpgv"],
  "video/jpm": ["*jpm", "jpgm"],
  "video/mj2": ["mj2", "mjp2"],
  "video/mp2t": ["ts"],
  "video/mp4": ["mp4", "mp4v", "mpg4"],
  "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"],
  "video/ogg": ["ogv"],
  "video/quicktime": ["qt", "mov"],
  "video/webm": ["webm"]
};

// index.ts
var { "application/wasm": wasm } = database_default;
export {
  wasm
};

There's probably something I can do to make this more efficient when only the default export ends up being used. But only exposing the default export would be a regression in functionality for tree shaking. As you can see with this example, it would be quite a big size regression in some cases.

@fabiospampinato
Copy link
Author

Makes sense, it's not as simple as I naively thought 🤔 Still it's probably worth addressing eventually.

@evanw evanw closed this as completed in 3f3d716 Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants