Skip to content

neves/webpack-merge-plus

Repository files navigation

Build Status codecov npm

Webpack Merge Plus

Extends webpack-merge to handle nested arrays and functions, recursively

Usage

This webpack.config.js can configure itself based on already defined attributes. See publicPath for example, it's based on devtool been set or not and use devServer host and port to build the url.

module.exports = require('mergePlus')([
  {
    context: __dirname,
    entry: './main.js',
    output: {
      filename: 'index.js'
    },
    devServer: {
      host: '0.0.0.0',
      port: 4000
    },
    devtool: process.env.NODE_ENV === 'production' ? null : 'eval-source-map'
  },

  ({context, devServer, devtool}) => {
    return {
      output: {        
        path: context + '/dist',
        publicPath: devtool ? `http://${devServer.host}:${devServer.port}/` : '/'
      }
    }
  }
])

You can run from example folder as webpack --config example/webpack.config.single-file.js

This makes more sense when splitted in multiple files. Check example folder for a sample.

Installation

Using npm

npm i -D webpack-merge-plus

Using yarn

yarn add -D webpack-merge-plus

Tests

This project uses Jest for testing.

After cloning and installing dependencies using yarn or npm, just run npm test.

Contribution

You're free to contribute to this project by submitting issues and/or pull requests. This project is test-driven, so keep in mind that every change and new feature should be covered by tests. Your name will be added to the hall of fame ;)

License

This project is licensed under MIT License

About

Helps organize webpack configs as nested files

Resources

License

Stars

Watchers

Forks

Packages

No packages published