Merge pull request #186 from Ayc0/feature/globals

Supports --globals config
This commit is contained in:
Leah 2018-08-14 13:10:36 +02:00 committed by GitHub
commit a7a6900f43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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(

View File

@ -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')