Next.js Discord

Discord Forum

import file based on the environment

Unanswered
Argentine ant posted this in #help-forum
Open in Discord
Argentine antOP
Hello,
to give some context, I have a module that sends events to a server and we provide JSON-Schema to validate the objects that leave the module in the unit tests.
I'd like this validation to be automated, and to be loaded only in the preprod environment, but I don't want these file imports to end up in the production build.
Basically, I'd like to know if there's a way to do this:

if (process.env.NODE_ENV === 'preprod') {
    import { json-schema-validation, validate } from 'validation-package'
}
...
if (process.env.NODE_ENV === 'preprod') {
    sendToEndPoint( validate(event, json-schema-validation ) )
}

4 Replies