Skip to content

Configuration management strategies #870

Closed

Description

@bebraw

I've tried various ways to structure configuration of projects where I used Webpack. I then trigger Webpack against specific configuration through NPM scripts. Example: "gh-pages": "webpack --config ./config/webpack.gh-pages.js". This allows sharing of configuration if I set up a module to contain the common bits and point at that from these specialized files. You can see this approach in action at reactabular.

The problem with this approach is that you'll quickly end up with a heap of separate configuration files which makes maintaining them harder than it should be. One alternative would be to push the configuration to a single file and deal with specialization there. The module would then export each (say config.dev, config.ghPages and so on). Then these bits could be wrapped into files that Webpack can consume. You would end up with something like this:

  • /config/common.js - Main bits + specialization happens here. Single file so easy to see what's going on.
  • /config/webpack-gh-pages.js - Just exports the specialized bit so Webpack can consume it
  • /config/webpack. ... .js - And so on

Even though an improvement, those Webpack specific wrapper modules feel like a kludge here. This made me to think. What if it was possible to extend Webpack's --config syntax a little bit? What if you could point to a specific export of a file directly? Ie. you would have webpack --config config.js:ghPages where the part after ":" would point at the specific module export.

The primary advantage of this is that it would allow you to maintain whole configuration in a single file while exposing the specialized versions of configuration easily for Webpack to consume.

Of course this can be solved with a little bit of user land tooling. Just need to write a small adapter between.

Activity

  1. bebraw commented on May 16, 2015

    @bebraw
    ContributorAuthor

    I've figured out a nice approach for this in react-component-boilerplate. The idea is simply to vary env and return correct configuration from webpack.config.js. Only problem is that this isn't cross-platform but you can't get everything...

  2. SimenB commented on May 16, 2015

    @SimenB
    Contributor
  3. bebraw commented on May 16, 2015

    @bebraw
    ContributorAuthor

    @SimenB Thanks for linking! I haven't seen that before. I've thought about pushing some utils of mine to a library but perhaps that won't be needed after all.

  4. SimenB commented on May 16, 2015

    @SimenB
    Contributor

    @bebraw Yeah, I just came over it because it's behind much of the magic I enjoyed in gulp-webpack-build. It might be nice if it was featured in the docs, as managing multiple webpack configs with common parts quickly becomes unwieldy.

  5. bebraw commented on May 16, 2015

    @bebraw
    ContributorAuthor

    @SimenB Yeah. I've set up a smart merge (recursive for objects, concat for arrays) just for that in my configurations. It's simple to understand what's going on.

    It would be better to find something cross-platform (ie. pass params to Webpack) but I think that'll have to wait for Webpack 2.0. I recall something is coming just to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions