0

I'm trying to create a config driven webapp using webpack and angular utilizing babel and es6.

I keep hitting a re-occuring problem that,I need my config.json in its own chunk and accessible from multiple controllers/components. However the difficulty is that I need it in human readable plain text form (aka not splashed with webpackJsonp etc and minified) just standard json.

Has anyone got any idea's?

Apologies in advance I'm completely new to webpack...

Tim.G
  • 271
  • 3
  • 3
  • Hey, try taking a look at this, see if it helps: https://stackoverflow.com/questions/38720133/webpack-bundle-dynamic-client-config/38737812#38737812 – Ambroos Aug 05 '16 at 08:35
  • Cheers for the link, although I'd prefer keeping it in a separate file as the config is quiet large and get edited quiet frequently. – Tim.G Aug 05 '16 at 12:26

1 Answers1

0

@Ambroos Thank you!!!

Although it wasn't precisely what I wanted it did do the job after fiddling with it a bit, figured I would put my findings here to help others...

Basically following the example Ambroos gave me you include:

  externals: {
     'appConfig': 'var sysConfig'
  },

Into you webpack config and construct you config like so:

var sysConfig = {
    "some": "config object"
}

Then instead of literally adding the json object in your index you simply load it in the traditional script loading method.

<script src="script location"></script>

Then require it where needed:

var sysConfig = require('appConfig');

This works for webpack dev and then for dist I simply use gulp to copy the config after the webpacking is complete.

Happy days!! :)

Tim.G
  • 271
  • 3
  • 3