google / schema-dts

JSON-LD TypeScript types for Schema.org vocabulary
Apache License 2.0
860 stars 32 forks source link

Installing as dependency (instead of devDependency) makes final bundle big #180

Open elledienne opened 2 years ago

elledienne commented 2 years ago

I noticed that this library lists typescript as a peer dependency in the package.json. At the same time, the README suggests installing this library by doing npm install schema-dts.

What happens then is that when I generate the bundle for my server, this library and also typescript are being bundled together with my server code, making the bundle quite big (typescript alone is 3MB minified).

Am I doing something wrong? Or should this library be installed as a devDependency instead?

Eyas commented 2 years ago

Hm, great point.

If you use import {...} from 'schema-dts';, your bundler might not optimize away that import, so you might still need the empty index.js that comes with schema-dts. If you use import type {...} from 'schema-dts';, then you can probably just install it as a dev dependency.

I think removing typescript as a peer dependency is probably right, to allow folks to use this library however way they like without being too restrictive about bundling/optimizing. The side-effect being that without typescript in your development toolchain, this library isn't helpful at all.

guy-borderless commented 11 months ago

This change is required to use schema-dts in a serverless setting like deno-deploy, since including the 38MB of typescript makes the bundle size prohibitive. Any update on when this will be released?