Skip to content

Commit 11a245e

Browse files
zefmanmontogeek
authored andcommitted
docs(configuration) Add externals examples (#2515)
Update the external docs with an example on how to combine the different syntaxes. I felt it was not clear how to achieve this from the existing docs.
1 parent 020d6b9 commit 11a245e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/content/configuration/externals.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ contributors:
77
- pksjce
88
- fadysamirsadek
99
- byzyk
10+
- zefman
1011
---
1112

1213
The `externals` configuration option provides a way of excluding dependencies from the output bundles. Instead, the created bundle relies on that dependency to be present in the consumer's environment. This feature is typically most useful to __library developers__, however there are a variety of applications for it.
@@ -148,5 +149,37 @@ module.exports = {
148149

149150
In this case any dependency named `jQuery`, capitalized or not, or `$` would be externalized.
150151

152+
### Combining syntaxes
153+
154+
Sometimes you may want to use a combination of the above syntaxes. This can be done in the following manner:
155+
156+
```js
157+
module.exports = {
158+
//...
159+
externals: [
160+
{
161+
// String
162+
react: 'react',
163+
// Object
164+
lodash : {
165+
commonjs: 'lodash',
166+
amd: 'lodash',
167+
root: '_' // indicates global variable
168+
},
169+
// Array
170+
subtract: ['./math', 'subtract']
171+
},
172+
// Function
173+
function(context, request, callback) {
174+
if (/^yourregex$/.test(request)){
175+
return callback(null, 'commonjs ' + request);
176+
}
177+
callback();
178+
},
179+
// Regex
180+
/^(jquery|\$)$/i
181+
]
182+
};
183+
```
151184

152185
For more information on how to use this configuration, please refer to the article on [how to author a library](/guides/author-libraries).

0 commit comments

Comments
 (0)