mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 19:43:20 +08:00
Updating webpack-merge to v4 (#20136)
This commit is contained in:
committed by
Ryan Cavanaugh
parent
a2f96b65de
commit
91c21b794a
43
types/webpack-merge/index.d.ts
vendored
43
types/webpack-merge/index.d.ts
vendored
@@ -1,25 +1,34 @@
|
||||
// Type definitions for webpack-merge
|
||||
// Type definitions for webpack-merge 4.1
|
||||
// Project: https://github.com/survivejs/webpack-merge
|
||||
// Definitions by: Simon Hartcher <https://github.com/deevus>
|
||||
// Definitions by: Simon Hartcher <https://github.com/deevus>, Matt Traynham <https://github.com/mtraynham>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
///<reference types="webpack" />
|
||||
import webpack = require('webpack');
|
||||
|
||||
declare module "webpack-merge" {
|
||||
import { Configuration } from "webpack";
|
||||
export = webpackMerge;
|
||||
|
||||
declare const webpackMerge: webpackMerge.WebpackMerge;
|
||||
|
||||
declare namespace webpackMerge {
|
||||
type CustomizeArrayFunction = (a: any[], b: any[], key: string) => any[] | null | undefined;
|
||||
type CustomizeObjectFunction = (a: {}, b: {}, key: string) => {} | null | undefined;
|
||||
type UniqueFunction = (field: string, fields: string[], keyFn: (field: any) => string) => CustomizeArrayFunction;
|
||||
interface CustomizeOptions {
|
||||
customizeArray?: CustomizeArrayFunction | UniqueFunction;
|
||||
customizeObject?: CustomizeObjectFunction;
|
||||
}
|
||||
type ConfigurationMergeFunction = (...configs: webpack.Configuration[]) => webpack.Configuration;
|
||||
type ConfigurationMergeConfigFunction = (customizeOptions: CustomizeOptions) => ConfigurationMergeFunction;
|
||||
type MergeFunction = ConfigurationMergeFunction | ConfigurationMergeConfigFunction;
|
||||
type MergeStrategy = 'prepend' | 'append' | 'replace';
|
||||
|
||||
interface WebpackMerge {
|
||||
/**
|
||||
* Merge multiple webpack configurations into one.
|
||||
*/
|
||||
(...configs: Configuration[]): Configuration;
|
||||
|
||||
/**
|
||||
* Merge multiple webpack configurations into one, with smart merging of loaders.
|
||||
*/
|
||||
smart(...configs: Configuration[]): Configuration;
|
||||
(...configs: webpack.Configuration[]): webpack.Configuration;
|
||||
(customizeOptions: CustomizeOptions): ConfigurationMergeFunction;
|
||||
unique: UniqueFunction;
|
||||
smart: ConfigurationMergeFunction;
|
||||
multiple: ConfigurationMergeFunction;
|
||||
strategy(options: {[field: string]: MergeStrategy}): ConfigurationMergeFunction;
|
||||
smartStrategy(options: {[key: string]: MergeStrategy}): ConfigurationMergeFunction;
|
||||
}
|
||||
|
||||
const merge: WebpackMerge;
|
||||
export = merge;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
@@ -19,4 +19,4 @@
|
||||
"index.d.ts",
|
||||
"webpack-merge-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
1
types/webpack-merge/tslint.json
Normal file
1
types/webpack-merge/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
25
types/webpack-merge/v0/index.d.ts
vendored
Normal file
25
types/webpack-merge/v0/index.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// Type definitions for webpack-merge
|
||||
// Project: https://github.com/survivejs/webpack-merge
|
||||
// Definitions by: Simon Hartcher <https://github.com/deevus>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
///<reference types="webpack" />
|
||||
|
||||
declare module "webpack-merge" {
|
||||
import { Configuration } from "webpack";
|
||||
|
||||
interface WebpackMerge {
|
||||
/**
|
||||
* Merge multiple webpack configurations into one.
|
||||
*/
|
||||
(...configs: Configuration[]): Configuration;
|
||||
|
||||
/**
|
||||
* Merge multiple webpack configurations into one, with smart merging of loaders.
|
||||
*/
|
||||
smart(...configs: Configuration[]): Configuration;
|
||||
}
|
||||
|
||||
const merge: WebpackMerge;
|
||||
export = merge;
|
||||
}
|
||||
26
types/webpack-merge/v0/tsconfig.json
Normal file
26
types/webpack-merge/v0/tsconfig.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"paths": {
|
||||
"webpack-merge": ["webpack-merge/v0"],
|
||||
"webpack-merge/*": ["webpack-merge/v0/*"]
|
||||
},
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"webpack-merge-tests.ts"
|
||||
]
|
||||
}
|
||||
12
types/webpack-merge/v0/webpack-merge-tests.ts
Normal file
12
types/webpack-merge/v0/webpack-merge-tests.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import merge = require("webpack-merge");
|
||||
import { Configuration } from "webpack";
|
||||
|
||||
const a: Configuration = {
|
||||
entry: "test.js"
|
||||
}
|
||||
const b: Configuration = {
|
||||
devtool: "source-map"
|
||||
}
|
||||
|
||||
const c = merge(a, b);
|
||||
const d = merge.smart(a, b);
|
||||
@@ -1,12 +1,61 @@
|
||||
import merge = require("webpack-merge");
|
||||
import { Configuration } from "webpack";
|
||||
import _ = require('lodash');
|
||||
import { Configuration, HotModuleReplacementPlugin, Plugin } from 'webpack';
|
||||
import webpackMerge = require('webpack-merge');
|
||||
|
||||
const a: Configuration = {
|
||||
entry: "test.js"
|
||||
}
|
||||
entry: 'test.js'
|
||||
};
|
||||
const b: Configuration = {
|
||||
devtool: "source-map"
|
||||
}
|
||||
devtool: 'source-map'
|
||||
};
|
||||
|
||||
const c = merge(a, b);
|
||||
const d = merge.smart(a, b);
|
||||
const c: Configuration = webpackMerge(a, b);
|
||||
const d: Configuration = webpackMerge.smart(a, b);
|
||||
const e: Configuration = webpackMerge.multiple(a, b);
|
||||
const f: Configuration = webpackMerge(
|
||||
{
|
||||
customizeArray(x: any[], y: any[], key: string): any[] | undefined {
|
||||
if (key === 'extensions') {
|
||||
return _.uniq([...x, ...y]);
|
||||
}
|
||||
// Fall back to default merging
|
||||
return undefined;
|
||||
},
|
||||
customizeObject(x: {}, y: {}, key: string): {} | undefined {
|
||||
if (key === 'module') {
|
||||
// Custom merging
|
||||
return _.merge({}, x, y);
|
||||
}
|
||||
|
||||
// Fall back to default merging
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
)(a, b);
|
||||
const g: Configuration = webpackMerge({
|
||||
customizeArray: webpackMerge.unique(
|
||||
'plugins',
|
||||
['HotModuleReplacementPlugin'],
|
||||
(plugin: Plugin) => plugin.constructor && plugin.constructor.name
|
||||
)
|
||||
})({
|
||||
plugins: [
|
||||
new HotModuleReplacementPlugin()
|
||||
]
|
||||
}, {
|
||||
plugins: [
|
||||
new HotModuleReplacementPlugin()
|
||||
]
|
||||
});
|
||||
const h: Configuration = webpackMerge.strategy(
|
||||
{
|
||||
entry: 'prepend', // or 'replace', defaults to 'append'
|
||||
'module.loaders': 'prepend'
|
||||
}
|
||||
)(a, b);
|
||||
const i: Configuration = webpackMerge.smartStrategy(
|
||||
{
|
||||
entry: 'prepend', // or 'replace'
|
||||
'module.loaders': 'prepend'
|
||||
}
|
||||
)(a, b);
|
||||
|
||||
Reference in New Issue
Block a user