ajv-formats icon indicating copy to clipboard operation
ajv-formats copied to clipboard

Using in the browser

Open sabrineChe opened this issue 4 years ago • 5 comments

I'm using the minified version of ajv7 in Javascript, and i want to support other formats, which are in the ajv-formats package. I want to import ajv-formats, which is written in typescript, to my Javascript project. Is there a possibility to make it ? Does a minified version of ajv-formats exist ?

sabrineChe avatar Apr 30 '21 10:04 sabrineChe

No, it is not provided. There is a compiled JS code though that it would be much more efficient to bundle with your code rather than use as a separate bundle as it's really small.

epoberezkin avatar May 04 '21 20:05 epoberezkin

Where can i find the compiled JS code? can you provide me the link please.

sabrineChe avatar May 05 '21 13:05 sabrineChe

@epoberezkin what if I just want to load ajv-formats in the browser, just like ajv-dist, no build/bundle involved?

mauriciolauffer avatar Apr 26 '22 01:04 mauriciolauffer

We could use it directly in the browser without any bundlers with a small ESM wrapper const ajv-formats = await import('https://unpkg.com/[email protected]/dist/index.js', that's a dynamic import, but a static one SHOULD work just as well. It doesn't because the current dist is only compiled to CommonJS.

In the meantime you can use Vite/ESBuild, it compiles just fine without any polyfills https://stackblitz.com/edit/vitejs-vite-pmhsra?file=src/main.ts

FossPrime avatar Apr 26 '22 16:04 FossPrime

Thanks for that, it was exactly what I've started testing after my comment :)

mauriciolauffer avatar Apr 27 '22 11:04 mauriciolauffer