I have a Node script that uses fs.readFileSync
several times to read various JSON5 configuration files that exist on the filesystem. These are read in, combined, manipulated, appended to, etc. based on certain criteria in the ENV variables. The output of this file is a JavaScript object via module.exports
.
I would like this script to be evaluated each time I run my Webpack build process and the output JS object made available in the bundle, so when my client React scripts do import { foo, bar } from 'config';
, those values can be accessed by the client code.
This seems like something that would a loader would solve, but I have been unable to get any of them working.
How can I evaluate a Node script during Webpack compile time and make its export be available to the compiled client code?