diff --git a/README.md b/README.md index 93f4466..a111bbd 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Just like `microbundle build`, but watches your source files and rebuilds on any -w, --watch Rebuilds on any change (default false) --target Specify your target environment (default node) --external Specify external dependencies, or 'none' + --globals Specify globals dependencies, or 'none' --compress Compress output using UglifyJS (default true) --strict Enforce undefined global context and add "use strict" --name Specify name exposed in UMD builds diff --git a/src/index.js b/src/index.js index 9c5fbee..71ec88b 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,14 @@ const safeVariableName = name => .toLowerCase() .replace(/((^[^a-zA-Z]+)|[^\w.-])|([^a-zA-Z0-9]+$)/g, ''), ); +const parseGlobals = globalStrings => { + const globals = {}; + globalStrings.split(',').forEach(globalString => { + const [localName, globalName] = globalString.split('='); + globals[localName] = globalName; + }); + return globals; +}; const WATCH_OPTS = { exclude: 'node_modules/**', @@ -243,6 +251,9 @@ function createConfig(options, entry, format, writeMeta) { } return globals; }, {}); + if (options.globals && options.globals !== 'none') { + globals = Object.assign(globals, parseGlobals(options.globals)); + } function replaceName(filename, name) { return resolve( diff --git a/src/prog.js b/src/prog.js index f627f13..a251c90 100644 --- a/src/prog.js +++ b/src/prog.js @@ -20,6 +20,8 @@ export default handler => { .option('--watch, -w', 'Rebuilds on any change', false) .option('--target', 'Specify your target environment', 'node') .option('--external', `Specify external dependencies, or 'none'`) + .option('--globals', `Specify globals dependencies, or 'none'`) + .example('microbundle --globals react=React,jquery=$') .option('--compress', 'Compress output using UglifyJS', true) .option('--strict', 'Enforce undefined global context and add "use strict"') .option('--name', 'Specify name exposed in UMD builds')