ajv icon indicating copy to clipboard operation
ajv copied to clipboard

Please document if/how standalone validation code generation can be run by Webpack

Open abraxxa opened this issue 4 years ago • 6 comments

What version of Ajv you are you using? 8.8.2

What problem do you want to solve? Get rid of 'unsafe-eval' in our CSP by using standalone validation code.

What do you think is the correct solution to problem? Let Webpack generate the standalone validation code on build.

Will you be able to implement it? Sadly no.

abraxxa avatar Nov 26 '21 11:11 abraxxa

Hi, i too am facing the same issue. Did you happen to find any solutions for this?

ahemed-haneen avatar Sep 30 '22 07:09 ahemed-haneen

Most likely, it would be easier to run compilation using ajv-cli as part of the build and then import compiled files from their target locations as you would do with your own code - I don’t think there will be anything special here with WebPack, compiled schema is a normal JavaScript code.

Depending on the schema, compiled files may have dependency on ajv runtime folder, but as long as ajv is available and can be resolved (via require) during the build it shouldn’t be a problem.

For example you can check out table package that uses build time schema compilation.

epoberezkin avatar Sep 30 '22 07:09 epoberezkin

i have created standalone code for my schema but my validation schema is quite large and hence i'm facing build issues. so i'm looking into how i can optimise that. as of now i have compiled and generated a standalone schema file. then bundled it using esbuild and imported it directly into the app. But this is increasing the app build time

ahemed-haneen avatar Sep 30 '22 07:09 ahemed-haneen

The approach is correct, and the build time will be slightly increased indeed - I don’t think much can be done about it, it’s what it is. Why do you need optimising it? It’s still should be under 1 min build time for most applications, am I right?

epoberezkin avatar Sep 30 '22 08:09 epoberezkin

after adding standalone schema the app:javascript size increased from 2.02 mb to 4.35mb. build times are close to 3 minutes and out of memory heap issues are also popping up.

ahemed-haneen avatar Sep 30 '22 08:09 ahemed-haneen

The approach is correct, and the build time will be slightly increased indeed - I don’t think much can be done about it, it’s what it is. Why do you need optimising it? It’s still should be under 1 min build time for most applications, am I right?

is there any provision to resolve ajv-formats or other similar require statements? cause export statements are throwing these errors image

ahemed-haneen avatar Oct 04 '22 18:10 ahemed-haneen