Skip to content

Commit

Permalink
Changes clone function used in webpack config to be a deep merge.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
itsjamie committed Jan 10, 2019
1 parent 259c6c0 commit 4fb5fb8
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions webpack.config.js
Expand Up @@ -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;
Expand All @@ -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/
}
]
}
};
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -86,7 +111,6 @@ function getPluginsForConfig(type, minify = false) {
}

function getConstantsForConfig (type) {

const gitCommitInfo = getGitCommitInfo();
const suffix = gitCommitInfo.shortCommit ? ('-' + gitCommitInfo.shortCommit) : '';

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4fb5fb8

Please sign in to comment.