Skip to content

Commit

Permalink
docs: add documentation for the webpack UMD configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoden committed Nov 29, 2018
1 parent 4d9270f commit 7f5aa78
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
16 changes: 15 additions & 1 deletion gulp/tasks/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ var CONFIG = require('../config.js');
// (just throw in foundation.js or foundation.min.js) or you should be using a build
// system.

// Generate plugin Externals config for UMD modules
//
// Generate the webpack "Externals" configuration for UMD modules.
// This tells webpack that the modules imported with the listed paths should not
// be included in the build but will be provided later from an external source.
//
// `umdExternals` generates for each module a configuration object with the
// given external source path/object to indicate to all import solutions where
// to retrieve the module. "root" is the global variable name to use in
// module-less environments (or in the namespace if given).
//
// See https://webpack.js.org/configuration/externals/#externals
//
var webpackExternalPlugins = Object.assign(
utils.umdExternals({
// Use the global jQuery object "jQuery" in module-less environments.
Expand Down Expand Up @@ -47,6 +58,9 @@ var webpackExternalPlugins = Object.assign(
})
);

// The webpack "output" configuration for UMD modules.
// Makes the modules be exported as UMD modules and within this global
// variable in module-less environments.
var webpackOutputAsExternal = {
library: [CONFIG.JS_BUNDLE_NAMESPACE, '[name]'],
libraryTarget: 'umd',
Expand Down
14 changes: 14 additions & 0 deletions gulp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ function getUmdEntry(name, config, format) {
return name;
}

/**
* Generate an configuration object for Webpack Externals for UMD modules.
* See: https://webpack.js.org/configuration/externals/#object
*
* @param {object} externals - Configuration object for external UMD modules.
* For each entry, a string or an object can be provided.
* - If a string, it is used for all module formats.
* - If an object, it is used as is and the module name is used for missing formats.
* @param {object} {} options- Additional options:
* - namespace {string} '' - Global variable in which the modules must be
* searched in instead of the root for module-less environments.
*
* @return {object} Generated configuration for Webpack Externals
*/
module.exports.umdExternals = function(externals, options) {
options = Object.assign({ namespace: '' }, options);

Expand Down

0 comments on commit 7f5aa78

Please sign in to comment.