webpack-merge
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
clone-deep | 4.0.1 | 3.12 kB | MIT | prod | |
wildcard | 2.0.1 | 3.98 kB | MIT | prod |
Webpack-merge is a powerful tool designed for the purpose of merging and configuring Webpack objects. It provides a merge
function that concatenates arrays and merges objects, creating a new object. If functions are encountered during merging, Webpack-merge executes them, runs the results through the algorithm, and then wraps the returned values within a function again. This makes Webpack-merge particularly useful for configuring Webpack, but it also has numerous applications beyond this.
In order to use Webpack-merge, you first need to import the module using const { merge } = require('webpack-merge');
. Then, you can use the merge
function to merge multiple objects together, resulting in a new combined object. A basic usage example is as follows:
const { merge } = require('webpack-merge');
// Merging object1, object2 and object3 into a new object
const output = merge(object1, object2, object3);
// Merging an array of objects. This works with all available functions
const output = merge([object1, object2, object3]);
For a more dynamic and complex Webpack configuration, you could use a switch case statement to merge different configurations depending on the provided mode:
const commonConfig = { ... };
const productionConfig = { ... };
const developmentConfig = { ... };
module.exports = (env, args) => {
switch(args.mode) {
case 'development':
return merge(commonConfig, developmentConfig);
case 'production':
return merge(commonConfig, productionConfig);
default:
throw new Error('No matching configuration was found!');
}
};
In this case, you would use webpack --mode development
or webpack --mode production
to choose your desired configuration.
Moreover, merge
behavior can be customized at a per-field level using mergeWithCustomize
.
The detailed documentation and code examples for Webpack-merge can be found directly in the package's README on its GitHub repository at https://github.com/survivejs/webpack-merge
. Comprehensive explanations and additional use cases for Webpack-merge are featured in the book "SurviveJS - Webpack 5", accessible at http://survivejs.com/
. Further support and expertise is also available through the consulting services provided by the creators and maintainers of Webpack-merge.