mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
Merge pull request #186 from Ayc0/feature/globals
Supports --globals config
This commit is contained in:
commit
a7a6900f43
@ -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
|
||||
|
||||
11
src/index.js
11
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(
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user