EventFellows's avatar

Conditionally 'require()' files in build process

Hi peers, I am really stuck here but I believe there is a simple solution that I just don't see at the moment. Appreciate your help on this. I am not so familar with what happends behind the scenes in Elixir exactly.

I have a pretty standard 5.3 setup that uses Elixir (gulp) to build an app.js file requiring different js files into the build process.

It essentially is setup like this.

require('./js-file-1');
require('./js-file-2');
require('./js-file-3');

require('./js-file-only-in-dev-environment');

BUT I need to conditionally require some files that only get required on development builds - so it is depending on the build environment.

I typically run export NODE_ENV=production && gulp --production which sets process.env.NODE_ENV = 'production' (based on a recommendation from @Jeffrey on some other discussion here)

BUT THIS WON'T WORK because this variable seems to only be available WITHIN the build process but NOT in the files that are concatenated during the build process:

require('./js-file-1');
require('./js-file-2');
require('./js-file-3');

if (process.env.NODE_ENV !== 'production') {
    require('./js-file-only-in-dev-environment');
}

SO, simple question: How can I conditionally require a js file in build process?

0 likes
0 replies

Please or to participate in this conversation.