Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class WebpackConfig {
this.providedVariables = {};
this.configuredFilenames = {};
this.aliases = {};
this.externals = {};
this.externals = [];

// Features/Loaders flags
this.useVersioning = false;
Expand Down Expand Up @@ -298,12 +298,12 @@ class WebpackConfig {
Object.assign(this.aliases, aliases);
}

addExternals(externals = {}) {
if (typeof externals !== 'object') {
throw new Error('Argument 1 to addExternals() must be an object.');
addExternals(externals = []) {
if (!Array.isArray(externals)) {
externals = [externals];
}

Object.assign(this.externals, externals);
this.externals = this.externals.concat(externals);
}

enableVersioning(enabled = true) {
Expand Down
2 changes: 1 addition & 1 deletion lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ConfigGenerator {
config.resolve.alias['react-dom'] = 'preact-compat';
}

config.externals = Object.assign({}, this.webpackConfig.externals);
config.externals = this.webpackConfig.externals;

return config;
}
Expand Down
19 changes: 5 additions & 14 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,24 +940,15 @@ describe('WebpackConfig object', () => {
it('Adds new externals', () => {
const config = createConfig();

expect(config.externals).to.deep.equals({});
expect(config.externals).to.deep.equals([]);

config.addExternals({ 'jquery': 'jQuery', 'react': 'react' });
config.addExternals({ 'lodash': 'lodash' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this test by adding, for example, another addExternal() that passes a regex?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update this to include a test for a regex.


expect(config.externals).to.deep.equals({
'jquery': 'jQuery',
'react': 'react',
'lodash': 'lodash'
});
});

it('Calling it with an invalid argument', () => {
const config = createConfig();

expect(() => {
config.addExternals('foo');
}).to.throw('must be an object');
expect(config.externals).to.deep.equals([
{ 'jquery': 'jQuery', 'react': 'react'},
{ 'lodash': 'lodash' }
]);
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ describe('The config-generator function', () => {

const actualConfig = configGenerator(config);

expect(actualConfig.externals).to.deep.equals({});
expect(actualConfig.externals).to.deep.equals([]);
});

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

const actualConfig = configGenerator(config);

expect(actualConfig.externals).to.deep.equals({
expect(actualConfig.externals).to.deep.equals([{
'jquery': 'jQuery',
'react': 'react'
});
}]);
});
});

Expand Down