3

I have a json config files that I want to not be bundled such that they are always loaded on app start. I can't seem to figure out how to properly do this.

Also in some cases the config file will contain a path to another file that has a require on it, not sure what webpack will do in that case.

    var path = require('path');
    var fs = require('fs');
    var webpack = require('webpack');

    var nodeModules = {};
    fs.readdirSync('node_modules')
      .filter(function(x) {
        return ['.bin'].indexOf(x) === -1;
      })
      .forEach(function(mod) {
        nodeModules[mod] = 'commonjs ' + mod;
      });

    nodeModules["config.json"] = "config";

    module.exports = {
      entry: './app.js',
      target: 'node',
      node: {
        __dirname: false,
        __filename: false
      },
      output: {
        path: __dirname,
        filename: 'backend.js'
      },
      externals: [ nodeModules]
    };
SergC
  • 161
  • 1
  • 7
  • Think you have to explain clearer: you're running in Node env? You don't want them to be bundled but you want them to load? How are you loading the json file(s)? What do you mean a json file has a require in it..? – Dominic Dec 09 '16 at 15:31
  • Sorry, I have a node app that I want to compress into one file but do not want the requires of ".json" files bundled, I want them to remain in the code so that they can be easily changed on the fly. Some config files will then have a path to different file and the app will do a require(config.externalJsonConfig) – SergC Dec 09 '16 at 15:35
  • I had to come up with a solution to a similar problem at my last job, maybe it will help you: http://stackoverflow.com/a/37675548/5436257. It refers to using TypeScript files as the configs, but I see no reason why it wouldn't work just as easily with JSON. – Joe Clay Dec 09 '16 at 16:10
  • Maybe this is helpful: http://stackoverflow.com/questions/33915826/exclude-module-from-webpack-minification – dreyescat Dec 10 '16 at 09:52
  • Did you ever find a solution to this? – ceebreenk May 22 '17 at 14:15

0 Answers0