From fd70406ab398d975b4377c3cdd09fb2a29efdc1a Mon Sep 17 00:00:00 2001 From: Gilad Gray Date: Mon, 16 Apr 2018 15:22:58 -0700 Subject: [PATCH] add all local packages to common externals (#2328) * add all local packages to common externals so they never get bundled in each other * use expanded externals syntax * whitespace --- packages/webpack-build-scripts/externals.js | 42 +++++++++++++++++++++ packages/webpack-build-scripts/index.js | 18 +-------- 2 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 packages/webpack-build-scripts/externals.js diff --git a/packages/webpack-build-scripts/externals.js b/packages/webpack-build-scripts/externals.js new file mode 100644 index 0000000000..2bdf081938 --- /dev/null +++ b/packages/webpack-build-scripts/externals.js @@ -0,0 +1,42 @@ +/* + * Copyright 2018 Palantir Technologies, Inc. All rights reserved. + * Licensed under the terms of the LICENSE file distributed with this project. + */ + +module.exports = externalize({ + "@blueprintjs/core": ["Blueprint", "Core"], + "@blueprintjs/icons": ["Blueprint", "Icons"], + "@blueprintjs/datetime": ["Blueprint", "Datetime"], + "@blueprintjs/labs": ["Blueprint", "Labs"], + "@blueprintjs/select": ["Blueprint", "Select"], + "@blueprintjs/table": ["Blueprint", "Table"], + "@blueprintjs/timezone": ["Blueprint", "Timezone"], + "classnames": "classNames", + "dom4": "window", + "jquery": "$", + "moment": "moment", + "moment-timezone": "moment", + "react": "React", + "react-transition-group": "ReactTransitionGroup", + "react-day-picker": "DayPicker", + "react-dom": "ReactDOM", +}); + +/** + * Generates a full webpack `external` listing declaring names for various module formats. + * @param {Record} externals + */ +function externalize(externals) { + const newExternals = {} + for (const pkgName in externals) { + if (externals.hasOwnProperty(pkgName)) { + newExternals[pkgName] = { + commonjs: pkgName, + commonjs2: pkgName, + amd: pkgName, + root: externals[pkgName], + } + } + } + return newExternals; +} diff --git a/packages/webpack-build-scripts/index.js b/packages/webpack-build-scripts/index.js index d308606c53..6981103a0c 100644 --- a/packages/webpack-build-scripts/index.js +++ b/packages/webpack-build-scripts/index.js @@ -5,24 +5,10 @@ const baseConfig = require("./webpack.config.base"); const karmaConfig = require("./webpack.config.karma"); +const COMMON_EXTERNALS = require("./externals"); module.exports = { baseConfig, karmaConfig, - COMMON_EXTERNALS: { - "@blueprintjs/core": "var Blueprint.Core", - "@blueprintjs/datetime": "var Blueprint.Datetime", - "@blueprintjs/labs": "var Blueprint.Labs", - "@blueprintjs/table": "var Blueprint.Table", - "classnames": "classNames", - "dom4": "window", - "jquery": "$", - "moment": "moment", - "moment-timezone": "moment", - "react": "React", - "react-transition-group": "ReactTransitionGroup", - "react-day-picker": "DayPicker", - "react-dom": "ReactDOM", - "tether": "Tether", - }, + COMMON_EXTERNALS, };