webpack-merge
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -0,1 +1,7 @@ | ||
0.6.0 / 2015-12-30 | ||
================== | ||
* Support `preLoaders` and `postLoaders`. Previously only `loaders` were supported. | ||
* Breaking: Change smart merging behavior for `loaders` field so that it prepends loaders instead of appending them. The benefit of this is that now it's possible to specialize loader setup in a predictable manner. For example you can have a linter set up at the root and expect it to become evaluated first always. | ||
0.5.1 / 2015-12-26 | ||
@@ -9,3 +15,3 @@ ================== | ||
* Push smart merging behind `merge.smart`. Now `merge` behaves exactly as in *0.3.0* series. | ||
* Breaking: Push smart merging behind `merge.smart`. Now `merge` behaves exactly as in *0.3.0* series. | ||
@@ -16,3 +22,3 @@ 0.4.0 / 2015-12-23 | ||
* Dropped changelog generator. It's better to write these by hand. | ||
* Added smart merging (@GreenGremlin) | ||
* Breaking: Added smart merging (@GreenGremlin) | ||
@@ -19,0 +25,0 @@ 0.3.2 / 2015-11-23 |
@@ -27,3 +27,4 @@ 'use strict'; | ||
})) { | ||
return [loader].concat(_toConsumableArray(mergedLoaders)); | ||
// prepend because of rtl (latter objects should be able to build the chain) | ||
return [].concat(_toConsumableArray(mergedLoaders), [loader]); | ||
} | ||
@@ -69,3 +70,3 @@ return mergedLoaders; | ||
return merge.apply(null, [{}].concat(args).concat([joinArrays.bind(null, function (a, b, key) { | ||
if (key === 'loaders') { | ||
if (['loaders', 'preLoaders', 'postLoaders'].indexOf(key) >= 0) { | ||
return b.reduce(reduceLoaders, a.slice()); | ||
@@ -72,0 +73,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Juho Vepsalainen <bebraw@gmail.com>", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "build": "babel src -d lib", |
@@ -122,3 +122,5 @@ [![build status](https://secure.travis-ci.org/survivejs/webpack-merge.png)](http://travis-ci.org/survivejs/webpack-merge) | ||
test: /\.js$/, | ||
loaders: ['babel', 'coffee'] | ||
// prepended because Webpack evaluated these from right to left! | ||
// this way you can specialize behavior and build the loader chain | ||
loaders: ['coffee', 'babel'] | ||
}] | ||
@@ -169,2 +171,3 @@ } | ||
test: /\.js$/, | ||
// prepended because Webpack evaluated these from right to left! | ||
loaders: ['babel', 'coffee'] | ||
@@ -171,0 +174,0 @@ }] |
@@ -19,3 +19,4 @@ const isArray = Array.isArray; | ||
if (mergedLoaders.every(l => loaderName !== l.match(loaderNameRe)[0])) { | ||
return [loader, ...mergedLoaders]; | ||
// prepend because of rtl (latter objects should be able to build the chain) | ||
return [...mergedLoaders, loader]; | ||
} | ||
@@ -65,3 +66,3 @@ return mergedLoaders; | ||
joinArrays.bind(null, function (a, b, key) { | ||
if (key === 'loaders') { | ||
if (['loaders', 'preLoaders', 'postLoaders'].indexOf(key) >= 0) { | ||
return b.reduce(reduceLoaders, a.slice()); | ||
@@ -68,0 +69,0 @@ } |
501
test.js
@@ -6,277 +6,298 @@ /* eslint-env mocha */ | ||
describe('Merge', function () { | ||
mergeTests(webpackMerge); | ||
const merge = webpackMerge; | ||
it('should merge recursive structures correctly', function () { | ||
normalMergeTests(merge, 'preLoaders'); | ||
normalMergeTests(merge, 'loaders'); | ||
normalMergeTests(merge, 'postLoaders'); | ||
mergeTests(merge); | ||
}); | ||
describe('Smart merge', function () { | ||
const merge = webpackMerge.smart; | ||
smartMergeTests(merge, 'preLoaders'); | ||
smartMergeTests(merge, 'loaders'); | ||
smartMergeTests(merge, 'postLoaders'); | ||
mergeTests(merge); | ||
}); | ||
function normalMergeTests(merge, loadersKey) { | ||
it('should merge recursive structures correctly with ' + loadersKey, function () { | ||
const a = { | ||
module: { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}, { | ||
test: /\.jade$/, | ||
loader: 'a' | ||
}] | ||
} | ||
module: {} | ||
}; | ||
a.module[loadersKey] = [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}, { | ||
test: /\.jade$/, | ||
loader: 'a' | ||
}]; | ||
const b = { | ||
module: { | ||
loaders: [{ | ||
test: /\.css$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.sass$/, | ||
loader: 'b' | ||
}] | ||
} | ||
module: {} | ||
}; | ||
b.module[loadersKey] = [{ | ||
test: /\.css$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.sass$/, | ||
loader: 'b' | ||
}]; | ||
const c = { | ||
module: { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}, { | ||
test: /\.jade$/, | ||
loader: 'a' | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.sass$/, | ||
loader: 'b' | ||
}] | ||
} | ||
module: {} | ||
}; | ||
c.module[loadersKey] = [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}, { | ||
test: /\.jade$/, | ||
loader: 'a' | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.sass$/, | ||
loader: 'b' | ||
}]; | ||
assert.deepEqual(webpackMerge(a, b), c); | ||
assert.deepEqual(merge(a, b), c); | ||
}); | ||
it('should not override loader string values', function () { | ||
const a = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}] | ||
}; | ||
const b = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}] | ||
}; | ||
const c = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}, { | ||
test: /\.js$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}] | ||
}; | ||
it('should not override loader string values with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
const c = {}; | ||
c[loadersKey] = [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}, { | ||
test: /\.js$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
assert.deepEqual(webpackMerge(a, b), c); | ||
assert.deepEqual(merge(a, b), c); | ||
}); | ||
it('should not append loaders', function () { | ||
const a = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}] | ||
}; | ||
const b = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['b'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}] | ||
}; | ||
const c = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['b'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}] | ||
}; | ||
it('should not append loaders with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['b'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
const c = {}; | ||
c[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['b'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
assert.deepEqual(webpackMerge(a, b), c); | ||
assert.deepEqual(merge(a, b), c); | ||
}); | ||
it('should duplicate loaders', function () { | ||
const a = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}] | ||
}; | ||
const b = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}] | ||
}; | ||
const c = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}] | ||
}; | ||
it('should duplicate loaders with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}]; | ||
const c = {}; | ||
c[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}]; | ||
assert.deepEqual(webpackMerge(a, b), c); | ||
assert.deepEqual(merge(a, b), c); | ||
}); | ||
it('should not 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'] | ||
}] | ||
}; | ||
const d = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a?1'] | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['a?2', 'b'] | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['a', 'b?3'] | ||
}] | ||
}; | ||
it('should not override query options for the same loader with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a?1'] | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a?2', 'b'] | ||
}]; | ||
const c = {}; | ||
c[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b?3'] | ||
}]; | ||
const d = {}; | ||
d[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a?1'] | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['a?2', 'b'] | ||
}, { | ||
test: /\.js$/, | ||
loaders: ['a', 'b?3'] | ||
}]; | ||
assert.deepEqual(webpackMerge(a, b, c), d); | ||
assert.deepEqual(merge(a, b, c), d); | ||
}); | ||
}); | ||
} | ||
describe('Smart merge', function () { | ||
const smartMerge = webpackMerge.smart; | ||
function smartMergeTests(merge, loadersKey) { | ||
it('should override loader string values with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
mergeTests(smartMerge); | ||
assert.deepEqual(merge(a, b), b); | ||
}); | ||
it('should override loader string values', function () { | ||
const a = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}] | ||
}; | ||
const b = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loader: 'b' | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}] | ||
}; | ||
it('should prepend loaders with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['b'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
const c = {}; | ||
c[loadersKey] = [{ | ||
test: /\.js$/, | ||
// loaders are evaluated from right to left so it makes sense to | ||
// prepend here!!! this is an exception given normally we want to | ||
// append instead. without this the loader order doesn't make | ||
// any sense in this case | ||
loaders: ['b', 'a'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
assert.deepEqual(smartMerge(a, b), b); | ||
assert.deepEqual(merge(a, b), c); | ||
}); | ||
it('should append loaders', function () { | ||
const a = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}] | ||
}; | ||
const b = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['b'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}] | ||
}; | ||
it('should prepend loader and loaders with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loader: 'a' | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['b'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
const c = {}; | ||
c[loadersKey] = [{ | ||
test: /\.js$/, | ||
// loaders are evaluated from right to left so it makes sense to | ||
// prepend here!!! this is an exception given normally we want to | ||
// append instead. without this the loader order doesn't make | ||
// any sense in this case | ||
loaders: ['b', 'a'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}]; | ||
assert.deepEqual(smartMerge(a, b), { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}, { | ||
test: /\.css$/, | ||
loader: 'b' | ||
}] | ||
}); | ||
assert.deepEqual(merge(a, b), c); | ||
}); | ||
it('should not duplicate loaders', function () { | ||
const a = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}] | ||
}; | ||
const b = { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}] | ||
}; | ||
it('should not duplicate loaders with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a'] | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}]; | ||
const c = {}; | ||
c[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}]; | ||
assert.deepEqual(smartMerge(a, b), { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b'] | ||
}] | ||
}); | ||
assert.deepEqual(merge(a, b), c); | ||
}); | ||
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'] | ||
}] | ||
}; | ||
it('should override query options for the same loader with ' + loadersKey, function () { | ||
const a = {}; | ||
a[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a?1'] | ||
}]; | ||
const b = {}; | ||
b[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a?2', 'b'] | ||
}]; | ||
const c = {}; | ||
c[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b?3'] | ||
}]; | ||
const d = {}; | ||
d[loadersKey] = [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b?3'] | ||
}]; | ||
assert.deepEqual(smartMerge(a, b, c), { | ||
loaders: [{ | ||
test: /\.js$/, | ||
loaders: ['a', 'b?3'] | ||
}] | ||
}); | ||
assert.deepEqual(merge(a, b, c), d); | ||
}); | ||
}); | ||
} | ||
@@ -283,0 +304,0 @@ function mergeTests(merge) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
525806
6374
207