From 4bb8a61c2329cc1ee5c08d61cd18cbf3219f155b Mon Sep 17 00:00:00 2001 From: Jozef Maxted Date: Thu, 13 Sep 2018 12:29:22 +0100 Subject: [PATCH] Update externals.md 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. --- src/content/configuration/externals.md | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/content/configuration/externals.md b/src/content/configuration/externals.md index 856ad56a3d58..93523d7a6c53 100644 --- a/src/content/configuration/externals.md +++ b/src/content/configuration/externals.md @@ -7,6 +7,7 @@ contributors: - pksjce - fadysamirsadek - byzyk + - zefman --- 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 = { In this case any dependency named `jQuery`, capitalized or not, or `$` would be externalized. +### Combining syntaxes + +Sometimes you may want to use a combination of the above syntaxes. This can be done in the following manner: + +```js +module.exports = { + //... + externals: [ + { + // String + react: 'react', + // Object + lodash : { + commonjs: 'lodash', + amd: 'lodash', + root: '_' // indicates global variable + }, + // Array + subtract: ['./math', 'subtract'] + }, + // Function + function(context, request, callback) { + if (/^yourregex$/.test(request)){ + return callback(null, 'commonjs ' + request); + } + callback(); + }, + // Regex + /^(jquery|\$)$/i + ] +}; +``` For more information on how to use this configuration, please refer to the article on [how to author a library](/guides/author-libraries).