UNPKG

@nurun-sf/spark-component

Version:

A tool for building spark components

77 lines (62 loc) 1.83 kB
'use strict'; var path = require('path'); var getClassName = require('./get-class-name'); var brand = require('./brand'); var LIBRARY_NAME = brand.name; function getJson(filepath) { return require(path.join(process.cwd(), filepath)); } var pkg = getJson('package.json'); var deps = {}; // If there are dependencies listed in package.json, add them. if (pkg.dependencies) { deps = pkg.dependencies; } // bower.json may not exist, so wrap in a try/catch. try { var bower = getJson('bower.json'); Object.assign(deps, bower.dependencies); } catch (e) {} // Allow packages to be bundled with the component. try { var packagesToBundle = getJson('bundle.json'); packagesToBundle.forEach(function (packageName) { delete deps[packageName]; }); } catch (e) {} // Mapping of dependencies which export themselves differently than the name // of the package. var SPECIAL = { jquery: 'jQuery', modernizr: 'Modernizr', underscore: '_', lodash: '_', 'tiny-emitter': 'TinyEmitter', }; // In case there is a new dependency which exposes itself differntly, allow // the above mapping to be added to. try { var customExternals = getJson('externals.json'); Object.assign(SPECIAL, customExternals); } catch (e) {} function getGlobalName(packageName) { if (packageName.startsWith(LIBRARY_NAME)) { return getClassName(packageName); } else if (SPECIAL[packageName]) { return SPECIAL[packageName]; } return packageName; } // Figure out external dependencies which should not be bundled. // https://github.com/webpack/webpack/tree/master/examples/externals module.exports = function () { return Object.keys(deps).reduce(function (obj, name) { obj[name] = { root: getGlobalName(name), commonjs: name, commonjs2: name, amd: name, }; return obj; }, {}); };