digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

Using jsonld.js with rollup #355

Closed lazka closed 4 years ago

lazka commented 4 years ago

Hey, more of a support question:

I'm trying to use jsonld.js with rollup for browser bundling and I was wondering if anyone has a working setup for it already or can give some hints on how to improve things (or can recommend an alternative library for parsing jsonld)

I can just import the minified version on npm, but that doesn't give me named exports and no treeshaking and jsonld.js is too large as is.

I have a minimal working rollup+jsonld setup here if someone wants to give it a try: https://github.com/lazka/jsonld-rollup-test

omirobarcelo commented 4 years ago

Yes, I have also issues with rollup. I'm trying to use jsonld in a Svelte web app.

These are my errors when building, using the library like import * as jsonld from "jsonld":

(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
core-js/fn/object/entries (imported by node_modules\jsonld\lib\index.js,  core-js/fn/object/entries?commonjs-external)
(!) Missing exports
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
src\App.svelte
compact is not exported by node_modules\jsonld\lib\index.js
360:   async function showData() {
361:     $$invalidate(1, show = true);
362:     const compacted = await jsonld.compact(doc, context);
                                        ^
363:     console.log(JSON.stringify(compacted, null, 2));

Using the minified version from node_modules liek @lazka does in his repo works, but it's not an ideal solution.

lazka commented 4 years ago

I've just updated the example repo to jsonld 3.x and rollup 2.x. Minified no-op bundle size is still at 230kb

davidlehn commented 4 years ago

Current focus is on 1.1 and related features. After that I hope to see the code switch over to ESM style and do some related cleanups. If using tree shaking tools then that should help with the size before even looking at other optimizations.

dlongley commented 4 years ago

Closing as a duplicate of #399.

lazka commented 4 years ago

Nice to see some progress, thanks!

lazka commented 3 years ago

I've updated my example repo now (newer versions, not using the minified bundle): https://github.com/lazka/jsonld-rollup-test

We are down from 215kb to 115kb minified, which is a nice improvements.