Skip to content

Commit abbf382

Browse files
committed
fix: array merge repeat
1 parent bd3e7a0 commit abbf382

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

lib/config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const WebpackTool = require('webpack-tool');
55
const webpack = WebpackTool.webpack;
66
const merge = WebpackTool.merge;
77
const utils = require('../utils/utils');
8+
const uniq = require('lodash.uniq');
89
const Logger = require('../utils/logger');
910
const Adapter = require('../utils/adapter');
1011

@@ -14,7 +15,11 @@ class Config {
1415
this.baseDir = config.baseDir || process.cwd();
1516
this.configList = [config];
1617
this.webpack = webpack;
17-
this.merge = merge;
18+
this.merge = merge({
19+
customizeArray(a, b, key) {
20+
return uniq([...a, ...b]);
21+
}
22+
});
1823
this.utils = utils;
1924
this.packs = {};
2025
this.webpackInfo = {};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
"lodash.clonedeep": "^4.5.0",
2929
"lodash.clonedeepwith": "^4.5.0",
3030
"lodash.get": "^4.4.2",
31-
"npm-install-webpack-plugin": "^4.0.5",
31+
"lodash.uniq": "^4.5.0",
3232
"node-noop": "^1.0.0",
33+
"npm-install-webpack-plugin": "^4.0.5",
3334
"postcss-loader": "^2.1.0",
3435
"progress-bar-webpack-plugin": "^1.10.0",
3536
"service-worker-precache-webpack-plugin": "^1.0.0",

test/client.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,4 +517,21 @@ describe('client.test.js', () => {
517517
expect(webpackConfig.devtool).to.equal('eval');
518518
});
519519
});
520+
describe('#webpack merge test', () => {
521+
it('should merge array uniq', () => {
522+
const builder = createBuilder({
523+
loaders : {
524+
scss: {
525+
options: {
526+
includePaths: [path.resolve(__dirname, 'app/web/asset'), path.resolve(__dirname, 'app/web/asset/style')],
527+
sourceMap: true,
528+
},
529+
},
530+
}
531+
});
532+
const webpackConfig = builder.create();
533+
const scssLoader = getLoaderByName('sass', webpackConfig.module.rules, /\.scss/);
534+
expect(scssLoader.use[3].options.includePaths.length).to.equal(2);
535+
});
536+
});
520537
});

utils/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ const queryString = require('querystring');
88
const mkdirp = require('mkdirp');
99
const cloneDeep = require('lodash.clonedeep');
1010
const cloneDeepWith = require('lodash.clonedeepwith');
11+
const uniq = require('lodash.uniq');
1112
const install = require('./install');
1213
const utils = Object.assign({}, {
1314
cloneDeep,
1415
cloneDeepWith,
16+
uniq,
1517
mkdirp,
1618
queryString
1719
}, install);

0 commit comments

Comments
 (0)