Skip to content

Commit 84a0dc0

Browse files
David EllingsworthDavid Ellingsworth
authored andcommitted
Store externals in an array. This fixes #471
1 parent b5750b2 commit 84a0dc0

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

lib/WebpackConfig.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class WebpackConfig {
4747
this.providedVariables = {};
4848
this.configuredFilenames = {};
4949
this.aliases = {};
50-
this.externals = {};
50+
this.externals = [];
5151

5252
// Features/Loaders flags
5353
this.useVersioning = false;
@@ -298,12 +298,12 @@ class WebpackConfig {
298298
Object.assign(this.aliases, aliases);
299299
}
300300

301-
addExternals(externals = {}) {
302-
if (typeof externals !== 'object') {
303-
throw new Error('Argument 1 to addExternals() must be an object.');
301+
addExternals(externals = []) {
302+
if (!Array.isArray(externals)) {
303+
externals = [externals];
304304
}
305305

306-
Object.assign(this.externals, externals);
306+
this.externals = this.externals.concat(externals);
307307
}
308308

309309
enableVersioning(enabled = true) {

lib/config-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class ConfigGenerator {
107107
config.resolve.alias['react-dom'] = 'preact-compat';
108108
}
109109

110-
config.externals = Object.assign({}, this.webpackConfig.externals);
110+
config.externals = this.webpackConfig.externals;
111111

112112
return config;
113113
}

test/WebpackConfig.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -940,24 +940,15 @@ describe('WebpackConfig object', () => {
940940
it('Adds new externals', () => {
941941
const config = createConfig();
942942

943-
expect(config.externals).to.deep.equals({});
943+
expect(config.externals).to.deep.equals([]);
944944

945945
config.addExternals({ 'jquery': 'jQuery', 'react': 'react' });
946946
config.addExternals({ 'lodash': 'lodash' });
947947

948-
expect(config.externals).to.deep.equals({
949-
'jquery': 'jQuery',
950-
'react': 'react',
951-
'lodash': 'lodash'
952-
});
953-
});
954-
955-
it('Calling it with an invalid argument', () => {
956-
const config = createConfig();
957-
958-
expect(() => {
959-
config.addExternals('foo');
960-
}).to.throw('must be an object');
948+
expect(config.externals).to.deep.equals([
949+
{ 'jquery': 'jQuery', 'react': 'react'},
950+
{ 'lodash': 'lodash' }
951+
]);
961952
});
962953
});
963954

test/config-generator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ describe('The config-generator function', () => {
471471

472472
const actualConfig = configGenerator(config);
473473

474-
expect(actualConfig.externals).to.deep.equals({});
474+
expect(actualConfig.externals).to.deep.equals([]);
475475
});
476476

477477
it('with addExternals()', () => {
@@ -485,10 +485,10 @@ describe('The config-generator function', () => {
485485

486486
const actualConfig = configGenerator(config);
487487

488-
expect(actualConfig.externals).to.deep.equals({
488+
expect(actualConfig.externals).to.deep.equals([{
489489
'jquery': 'jQuery',
490490
'react': 'react'
491-
});
491+
}]);
492492
});
493493
});
494494

0 commit comments

Comments
 (0)