diff --git a/packages/scripts/@types/webpack-merge.d.ts b/packages/scripts/@types/webpack-merge.d.ts index 94da7316a..7d1976e90 100644 --- a/packages/scripts/@types/webpack-merge.d.ts +++ b/packages/scripts/@types/webpack-merge.d.ts @@ -1,6 +1,19 @@ declare module 'webpack-merge' { import * as webpack from 'webpack'; + interface customizeArray { + (a:any[], b:any[], key:string):any[] + } + interface customizeObject { + (a:Object, b:Object, key:string):Object + } + interface merge { + // Main callable function interface + (...configs: webpack.Configuration[]):webpack.Configuration; + (configs:webpack.Configuration[]):webpack.Configuration; + } function merge(...configs: webpack.Configuration[]):webpack.Configuration; + function merge(configs:webpack.Configuration[]):webpack.Configuration; + function merge(customizer:{customizeArray:customizeArray, customizeObject:customizeObject}):merge; namespace merge { function smart(...configs: webpack.Configuration[]):webpack.Configuration; } diff --git a/packages/scripts/src/config/CreateWebpackConfig.ts b/packages/scripts/src/config/CreateWebpackConfig.ts index 16ac4a8eb..221b9f482 100644 --- a/packages/scripts/src/config/CreateWebpackConfig.ts +++ b/packages/scripts/src/config/CreateWebpackConfig.ts @@ -182,7 +182,12 @@ export class CreateWebpackConfig { // Merge options if needed // Loose comparison because it could very well be undefined if (file.webpackConfig != null) { - config = webpackMerge(config, file.webpackConfig); + // If it is a function + if (typeof file.webpackConfig === 'function') { + config = file.webpackConfig(config, webpackMerge); + } else { + config = webpackMerge(config, file.webpackConfig); + } } return config; diff --git a/packages/scripts/src/config/project.config.default.ts b/packages/scripts/src/config/project.config.default.ts index bcd67b316..5e1d9cf4a 100644 --- a/packages/scripts/src/config/project.config.default.ts +++ b/packages/scripts/src/config/project.config.default.ts @@ -1,4 +1,5 @@ import webpack from 'webpack'; +import merge from 'webpack-merge'; import { PresetOptions } from '@wpackio/babel-preset-base/lib/preset'; @@ -30,7 +31,12 @@ export interface EntryConfig { export interface FileConfig { name: string; entry: EntryConfig; - webpackConfig?: webpack.Configuration; + webpackConfig?: + | webpack.Configuration + | (( + config: webpack.Configuration, + api: merge + ) => webpack.Configuration); } export type webpackOptionsOverrideFunction = (