MCPcopy Index your code
hub / github.com/developit/microbundle / createConfig

Function createConfig

src/index.js:326–699  ·  view source on GitHub ↗
(options, entry, format, writeMeta)

Source from the content-addressed store, hash-verified

324const shebang = {};
325
326function createConfig(options, entry, format, writeMeta) {
327 let { pkg } = options;
328
329 /** @type {(string|RegExp)[]} */
330 let external = ['dns', 'fs', 'path', 'url'];
331
332 /** @type {Record<string, string>} */
333 let outputAliases = {};
334
335 const moduleAliases = options.alias ? parseAliasArgument(options.alias) : [];
336 const aliasIds = moduleAliases.map(alias => alias.find);
337
338 // We want to silence rollup warnings for node builtins as we rollup-node-resolve threats them as externals anyway
339 // @see https://github.com/rollup/plugins/tree/master/packages/node-resolve/#resolving-built-ins-like-fs
340 if (options.target === 'node') {
341 external = [/node:.*/].concat(builtinModules);
342 }
343
344 const peerDeps = Object.keys(pkg.peerDependencies || {});
345 if (options.external === 'none') {
346 // bundle everything (external=[])
347 } else if (options.external) {
348 external = external.concat(peerDeps).concat(
349 // CLI --external supports regular expressions:
350 options.external.split(',').map(str => new RegExp(str)),
351 );
352 } else {
353 external = external
354 .concat(peerDeps)
355 .concat(Object.keys(pkg.dependencies || {}));
356 }
357
358 let globals = external.reduce((globals, name) => {
359 // Use raw value for CLI-provided RegExp externals:
360 if (name instanceof RegExp) name = name.source;
361
362 // valid JS identifiers are usually library globals:
363 if (name.match(/^[a-z_$][a-z0-9_\-$]*$/)) {
364 globals[name] = camelCase(name);
365 }
366 return globals;
367 }, {});
368 if (options.globals && options.globals !== 'none') {
369 globals = Object.assign(globals, parseMappingArgument(options.globals));
370 }
371
372 let defines = {};
373 if (options.define) {
374 defines = Object.assign(
375 defines,
376 parseMappingArgument(options.define, toReplacementExpression),
377 );
378 }
379
380 const modern = format === 'modern';
381
382 // let rollupName = safeVariableName(basename(entry).replace(/\.js$/, ''));
383

Callers 1

microbundleFunction · 0.85

Calls 9

parseAliasArgumentFunction · 0.90
parseMappingArgumentFunction · 0.90
normalizeMinifyOptionsFunction · 0.90
shouldCssModulesFunction · 0.90
cssModulesConfigFunction · 0.90
isTruthyFunction · 0.90
loadNameCacheFunction · 0.85
getMainFunction · 0.85
getDeclarationDirFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…