title: How can I automatically load all JSON files from a given directory in Webpack?
body: <p>Edit: There is <a href="https://stackoverflow.com/questions/29421409/how-to-load-all-files-in-a-subdirectories-using-webpack-without-require-statemen">an existing question</a> about loading multiple files but does not adequately address how to combine JSON files into a single object. See answer below. This question is not a duplicate.</p>
  
  <hr>
  
  <p>I have a directory with 100 or so JSON files that I want to load into my js app, which is bundled via WebPack. </p>
  
  <p>I could go through the initial pain of writing out the following:</p>
  
  <pre><code>let data = [
      require('json!./Mocks/0.json'),
      require('json!./Mocks/1.json'),
      // 2 - 98...
      require('json!./Mocks/99.json'),
      require('json!./Mocks/error.json'),
      require('json!./Mocks/foo.json'),
  ];
  </code></pre>
  
  <p>But I would much rather grab everything automatically so that I don't have to update my code when I add/remove JSON files to that directory in the future. How can I do this?</p>