Skip to content

Commit

Permalink
feat: accept function for webpackConfig
Browse files Browse the repository at this point in the history
Using a function and passing existing config to webpackConfig opens
many possibilities than just using webpackMerge out of the box.

See #7
  • Loading branch information
swashata committed Oct 19, 2018
1 parent b60fcba commit 3466fe7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/scripts/@types/webpack-merge.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/scripts/src/config/CreateWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion packages/scripts/src/config/project.config.default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import webpack from 'webpack';
import merge from 'webpack-merge';

import { PresetOptions } from '@wpackio/babel-preset-base/lib/preset';

Expand Down Expand Up @@ -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 = (
Expand Down

0 comments on commit 3466fe7

Please sign in to comment.