Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webpack-merge

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-merge - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

.babelrc

42

CHANGELOG.md

@@ -0,9 +1,16 @@

0.4.0 / 2015-12-23
==================
* Dropped changelog generator. It's better to write these by hand.
* Added smart merging (@GreenGremlin)
0.3.2 / 2015-11-23
==================
* Tweaked changelog generator process.
0.3.1 / 2015-11-23
==================
* Update changelog
* 0.3.1
* Generate changelog
I set up a `prepublish` script to generate it automatically.
Closes [#3](https://github.com/survivejs/webpack-merge/issues/3).
* Added changelog generator.

@@ -13,5 +20,4 @@ 0.3.0 / 2015-11-13

* 0.3.0
* Improve formatting
* Allow an arbitrary amount of objects to be merged
* Improved formatting
* Allowed an arbitrary amount of objects to be merged

@@ -21,9 +27,4 @@ 0.2.0 / 2015-08-30

* 0.2.0
* Add @montogeek to contributors
* Merge pull request [#2](https://github.com/survivejs/webpack-merge/issues/2) from montogeek/master
Only require lodash modules used by the package
* Remove lodash.isarray dependency, use Array.isArray standard object
* Require only lodash modules used
* Add missing ...
* Only require lodash modules used by the package (@montogeek)
* Removed lodash.isarray dependency, use Array.isArray standard object

@@ -33,4 +34,3 @@ 0.1.3 / 2015-08-10

* 0.1.3
* Improve README example
* Improved README example

@@ -40,4 +40,3 @@ 0.1.2 / 2015-07-01

* 0.1.2
* Simplify example
* Simplified example

@@ -47,4 +46,3 @@ 0.1.1 / 2015-06-26

* 0.1.1
* Fix travis link
* Fixed travis link

@@ -54,4 +52,2 @@ 0.1.0 / 2015-06-26

* 0.1.0
* Initial implementation
* Initial commit

@@ -5,10 +5,14 @@ {

"author": "Juho Vepsalainen <bebraw@gmail.com>",
"version": "0.3.2",
"version": "0.4.0",
"scripts": {
"build": "babel src -d lib",
"watch": "babel src --watch -d lib",
"test": "mocha ./test",
"watch": "mocha ./test --watch",
"generate_changelog": "changelog all > CHANGELOG.md",
"postpublish": "npm run generate_changelog && git commit --allow-empty -am \"Update changelog\""
"lint": "eslint .",
"watch:test": "mocha ./test --watch",
"preversion": "npm run lint && npm test && npm run build && git commit --allow-empty -am \"Update lib\""
},
"main": "lib/index.js",
"dependencies": {
"lodash.find": "^3.2.1",
"lodash.isplainobject": "^3.2.0",

@@ -18,3 +22,6 @@ "lodash.merge": "^3.3.2"

"devDependencies": {
"changelog": "^1.0.7",
"babel-cli": "^6.3.17",
"babel-preset-es2015": "^6.3.13",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^2.1.1",
"mocha": "^2.2.5"

@@ -21,0 +28,0 @@ },

[![build status](https://secure.travis-ci.org/survivejs/webpack-merge.png)](http://travis-ci.org/survivejs/webpack-merge)
# webpack-merge - Merge designed for Webpack
Normal merge function isn't that useful with webpack configuration as it will override object keys and arrays by default. It is more beneficial to concatenate arrays instead. This little helper achieves just that. Consider the example below:
Normal merge function isn't that useful with webpack configuration as it will override object keys and arrays by default. It is more beneficial to concatenate arrays instead. This little helper achieves just that.

@@ -29,2 +29,3 @@ ## API

```javascript
var path = require('path');
var merge = require('webpack-merge');

@@ -35,3 +36,3 @@

var common = {
entry: [path.join(ROOT_PATH, 'app/main.jsx')],
entry: path.join(__dirname, 'app'),
...

@@ -73,11 +74,130 @@ module: {

Check out [SurviveJS - Webpack and React](http://survivejs.com/) to dig deeper into the topic.
> Check out [SurviveJS - Webpack and React](http://survivejs.com/) to dig deeper into the topic.
## Smart Merging of Loaders
Webpack-merge tries to be smart about merging loaders. Loaders with matching tests will be merged into a single loader value.
**Loader string values `loader: 'babel'` override each other.**
```javascript
merge({
loaders: [{
test: /\.js$/,
loader: 'babel'
}]
}, {
loaders: [{
test: /\.js$/,
loader: 'coffee'
}]
});
// will become
{
loaders: [{
test: /\.js$/,
loader: 'coffee'
}]
}
```
**Loader array values `loaders: ['babel']` will be merged, without duplication.**
```javascript
merge({
loaders: [{
test: /\.js$/,
loaders: ['babel']
}]
}, {
loaders: [{
test: /\.js$/,
loaders: ['coffee']
}]
});
// will become
{
loaders: [{
test: /\.js$/,
loaders: ['babel', 'coffee']
}]
}
```
**Loader query strings `loaders: ['babel?plugins[]=object-assign']` will be overridden**
```javascript
merge({
loaders: [{
test: /\.js$/,
loaders: ['babel?plugins[]=object-assign']
}]
}, {
loaders: [{
test: /\.js$/,
loaders: ['babel', 'coffee']
}]
});
// will become
{
loaders: [{
test: /\.js$/,
loaders: ['babel', 'coffee']
}]
}
```
**Loader arrays in source values will have loader strings merged into them.**
```javascript
merge({
loaders: [{
test: /\.js$/,
loader: 'babel'
}]
}, {
loaders: [{
test: /\.js$/,
loaders: ['coffee']
}]
});
// will become
{
loaders: [{
test: /\.js$/,
loaders: ['babel', 'coffee']
}]
}
```
**Loader strings in source values will always override.**
```javascript
merge({
loaders: [{
test: /\.js$/,
loaders: ['babel']
}]
}, {
loaders: [{
test: /\.js$/,
loader: 'coffee'
}]
});
// will become
{
loaders: [{
test: /\.js$/,
loader: 'coffee'
}]
}
```
## Contributors
* [Fernando Montoya](https://github.com/montogeek) - Use separate lodash functions instead of the core package. Faster to install this way.
* [Jonathan Felchlin](https://github.com/GreenGremlin) - Smart merging for loaders.
## License
webpack-merge is available under MIT. See LICENSE for more details.
*webpack-merge* is available under MIT. See LICENSE for more details.

@@ -1,12 +0,11 @@

'use strict';
var assert = require('assert');
/* eslint-env mocha */
const assert = require('assert');
const merge = require('./lib');
var merge = require('./');
describe('Merge', function() {
it('should override objects', function() {
var a = {
foo: 'a',
describe('Merge', function () {
it('should override objects', function () {
const a = {
foo: 'a'
};
var b = {
const b = {
foo: 'b'

@@ -18,8 +17,8 @@ };

it('should append arrays', function() {
var a = {
foo: ['a'],
it('should append arrays', function () {
const a = {
foo: ['a']
};
var b = {
foo: ['b'],
const b = {
foo: ['b']
};

@@ -32,8 +31,8 @@

it('should append arrays without mutating', function() {
var a = {
foo: ['a'],
it('should append arrays without mutating', function () {
const a = {
foo: ['a']
};
var b = {
foo: ['b'],
const b = {
foo: ['b']
};

@@ -49,11 +48,11 @@

it('should override objects of multiple objects', function() {
var a = {
foo: 'a',
it('should override objects of multiple objects', function () {
const a = {
foo: 'a'
};
var b = {
const b = {
foo: 'b'
};
var c = {
foo: 'c',
const c = {
foo: 'c'
};

@@ -64,11 +63,11 @@

it('should append arrays of multiple objects', function() {
var a = {
foo: ['a'],
it('should append arrays of multiple objects', function () {
const a = {
foo: ['a']
};
var b = {
foo: ['b'],
const b = {
foo: ['b']
};
var c = {
foo: ['c'],
const c = {
foo: ['c']
};

@@ -80,2 +79,101 @@

});
it('should overwride loader string values', function () {
const a = {
loaders: [{
test: /\.js$/,
loader: 'a'
}]
};
const b = {
loaders: [{
test: /\.js$/,
loader: 'b'
}, {
test: /\.css$/,
loader: 'b'
}]
};
assert.deepEqual(merge(a, b), b);
});
it('should append loaders', function () {
const a = {
loaders: [{
test: /\.js$/,
loaders: ['a']
}]
};
const b = {
loaders: [{
test: /\.js$/,
loaders: ['b']
}, {
test: /\.css$/,
loader: 'b'
}]
};
assert.deepEqual(merge(a, b), {
loaders: [{
test: /\.js$/,
loaders: ['a', 'b']
}, {
test: /\.css$/,
loader: 'b'
}]
});
});
it('should not duplicate loaders', function () {
const a = {
loaders: [{
test: /\.js$/,
loaders: ['a']
}]
};
const b = {
loaders: [{
test: /\.js$/,
loaders: ['a', 'b']
}]
};
assert.deepEqual(merge(a, b), {
loaders: [{
test: /\.js$/,
loaders: ['a', 'b']
}]
});
});
it('should override query options for the same loader', function () {
const a = {
loaders: [{
test: /\.js$/,
loaders: ['a?1']
}]
};
const b = {
loaders: [{
test: /\.js$/,
loaders: ['a?2', 'b']
}]
};
const c = {
loaders: [{
test: /\.js$/,
loaders: ['a', 'b?3']
}]
};
assert.deepEqual(merge(a, b, c), {
loaders: [{
test: /\.js$/,
loaders: ['a', 'b?3']
}]
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc