From 4fb5fb893caa78041f71029c20d5cc975f92bbdd Mon Sep 17 00:00:00 2001 From: Jamie Stackhouse Date: Thu, 10 Jan 2019 10:49:17 -0400 Subject: [PATCH] Changes clone function used in webpack config to be a deep merge. This fixes an issue where light-dist / light defined their own resolve property causing them to not get the base config resolve for extensions, etc. Includes a few minor lint fixes that popped in my editor as well. --- webpack.config.js | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 233bfc33c62..7d9fd768d76 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,29 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl const getGitVersion = require('git-tag-version'); const getGitCommitInfo = require('git-commit-info'); -const clone = (...args) => Object.assign({}, ...args); +const isObject = (item) => { + return (item && typeof item === 'object' && !Array.isArray(item)); +}; + +const mergeDeep = (target, ...sources) => { + if (!sources.length) return target; + const source = sources.shift(); + + if (isObject(target) && isObject(source)) { + for (const key in source) { + if (isObject(source[key])) { + if (!target[key]) Object.assign(target, { [key]: {} }); + mergeDeep(target[key], source[key]); + } else { + Object.assign(target, { [key]: source[key] }); + } + } + } + + return mergeDeep(target, ...sources); +}; + +const clone = (...args) => mergeDeep({}, ...args); /* Allow to customise builds through env-vars */ const env = process.env; @@ -22,14 +44,17 @@ const baseConfig = { entry: './src/hls', resolve: { // Add `.ts` as a resolvable extension. - extensions: [".ts", ".js"] + extensions: ['.ts', '.js'] }, module: { strictExportPresence: true, rules: [ // all files with a `.ts` extension will be handled by `ts-loader` - { test: /\.ts?$/, loader: "ts-loader" }, - { test: /\.js?$/, exclude: [/node_modules/], loader: "ts-loader" }, + { + test: /\.(ts|js)x?$/, + loader: 'ts-loader', + exclude: /node_modules/ + } ] } }; @@ -47,7 +72,7 @@ const demoConfig = clone(baseConfig, { library: 'HlsDemo', libraryTarget: 'umd', libraryExport: 'default', - globalObject: 'this' // https://github.com/webpack/webpack/issues/6642#issuecomment-370222543 + globalObject: 'this' // https://github.com/webpack/webpack/issues/6642#issuecomment-370222543 }, optimization: { minimize: false @@ -56,7 +81,7 @@ const demoConfig = clone(baseConfig, { devtool: 'source-map' }); -function getPluginsForConfig(type, minify = false) { +function getPluginsForConfig (type, minify = false) { // common plugins. const defineConstants = getConstantsForConfig(type); @@ -86,7 +111,6 @@ function getPluginsForConfig(type, minify = false) { } function getConstantsForConfig (type) { - const gitCommitInfo = getGitCommitInfo(); const suffix = gitCommitInfo.shortCommit ? ('-' + gitCommitInfo.shortCommit) : ''; @@ -212,7 +236,6 @@ multiConfig.push(demoConfig); // webpack matches the --env arguments to a string; for example, --env.debug.min translates to { debug: true, min: true } module.exports = (envArgs) => { - let configs; if (!envArgs) {