import file based on the environment
Unanswered
Argentine ant posted this in #help-forum
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:
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
@Argentine ant 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 ) )
}
you can use the dynamic function to import specific stuff into your component depending on some condition like this:
if(someCondition)
const imported = dynamic(() => import("your/path")Argentine antOP
ho nice, I hadn't thought of that, I'll try this, thank you very much!
@Argentine ant tried?