hyperjump-io / json-schema

JSON Schema Validation, Annotation, and Bundling. Supports Draft 04, 06, 07, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1
https://json-schema.hyperjump.io/
MIT License
221 stars 21 forks source link

Size is too large ( it that possiable to have less then 1MB package size ) #13

Closed hanoj-budime closed 2 years ago

hanoj-budime commented 2 years ago

image

jdesrosiers commented 2 years ago

This packages is actually very small and I take great care to make sure that it stays that way. See https://bundlephobia.com/package/@hyperjump/json-schema@0.18.3 for a more accurate assessment than what you see on npmjs.com. The current version is about 150KB raw, 79KB minified, and 13KB compressed.

The reason it appears to be so big is because I package several pre-built bundles in different formats for people who aren't using bundlers can include the package using unpkg: https://unpkg.com/browse/@hyperjump/json-schema@0.18.3/dist/. These builds will not be included when this code gets bundled into your app.

hanoj-budime commented 2 years ago

Hi @jdesrosiers,

Thanks for your response.

But we are using this package in our Node.js Project ( package version is @hyperjump/json-schema@0.11.1 ).

After deployment, this project in AWS lambda shows project size is more then 3.2 MB.

Because of this https://bundlephobia.com/package/@hyperjump/json-schema@0.11.1

Can please help me on this.

jdesrosiers commented 2 years ago

Ah, now it makes sense. It would be that large on disk. I never thought of that as an issue, but I assume AWS lambda has limits on how big a lambda can be.

I'm not sure what can be done about that other than removing the pre-built bundles, but I'm not sure I want to do that. I might be able to do something with a postinstall script that deletes the "dist" directory, but I don't know if that would work. I'll look into it and see if there's anything I can do.

jdesrosiers commented 2 years ago

I added a postinstall script to remove the dist directory and it seems to work. The pre-bundled distributions are still available on unpkg and the final size in node_modules including dependencies is under 600KB. The npm install command will still download the whole thing, but will delete the files that aren't needed for a node application. I don't know if that ends up helping in you situation or not. It depends on how AWS lambda counts size.

Give it a try with version 0.18.4 and let me know if it works.

hanoj-budime commented 2 years ago

Thanks, @jdesrosiers.

Now I can see the Package size reduce.

But this works on pipeline & Linux, not in Windows right?

hanoj-budime commented 2 years ago

I added a postinstall script to remove the dist directory and it seems to work. The pre-bundled distributions are still available on unpkg and the final size in node_modules including dependencies is under 600KB. The npm install command will still download the whole thing, but will delete the files that aren't needed for a node application. I don't know if that ends up helping in you situation or not. It depends on how AWS lambda counts size.

Give it a try with version 0.18.4 and let me know if it works.

Worked

hanoj-budime commented 2 years ago

Worked For Me ( in Linux, But not in Windows ).

Maybe it's fine if you just provide steps to write a post-install script in their owner project. instead of doing here.

jdesrosiers commented 2 years ago

Thanks for checking. I always forget windows exists. I'm pretty sure I know what I have to do to make it work everywhere.