From e75f2831a3f347a88e604044fa21a5360940698e Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Sun, 15 Jan 2017 23:22:20 +0800 Subject: [PATCH 1/3] feat: add performance options to webpack --- webpack/index.d.ts | 23 ++++++++++++++++++++++- webpack/webpack-tests.ts | 13 +++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index c2a435da6e..820e76866b 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for webpack 2.2 // Project: https://github.com/webpack/webpack -// Definitions by: Qubo , Matt Lewis +// Definitions by: Qubo , Matt Lewis , Benjamin Lim // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -66,6 +66,8 @@ declare namespace webpack { plugins?: Plugin[]; /** Stats options for logging */ stats?: compiler.StatsToStringOptions; + /** Performance options */ + performance?: PerformanceOptions; } interface Entry { @@ -845,6 +847,25 @@ declare namespace webpack { type CompilerCallback = (err: Error, stats: Stats) => void } + + interface PerformanceOptions { + /** + * Turns hints on/off. In addition, tells webpack to throw either an error or a warning when hints are found. This property is set to "warning" by default. + */ + hints?: boolean | 'error' | 'warning'; + /** + * An entrypoint represents all assets that would be utilized during initial load time for a specific entry. This option controls when webpack should emit performance hints based on the maximum entrypoint size. The default value is 250000 (bytes). + */ + maxEntryPointSize?: number; + /** + * An asset is any emitted file from webpack. This option controls when webpack emits a performance hint based on individual asset size. The default value is 250000 (bytes). + */ + maxAssetSize?: number; + /** + * This property allows webpack to control what files are used to calculate performance hints. + */ + assetFilter?: (assetFilename: string) => boolean; + } } declare var webpack: webpack.Webpack; diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index 8cdb92c94b..3900524ec5 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -490,3 +490,16 @@ configuration = { const resolve: webpack.Resolve = { cachePredicate: 'boo' // why does this test _not_ fail!? } + +const performance: webpack.PerformanceOptions = { + hints: 'error', + maxEntryPointSize: 400000, + maxAssetSize: 100000, + assetFilter: function(assetFilename) { + return assetFilename.endsWith('.js'); + }, +}; + +configuration = { + performance, +}; From 73e0c1cae3746f17aa2ddefcd5ebae34a923c1cf Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Sun, 15 Jan 2017 23:23:05 +0800 Subject: [PATCH 2/3] style: fix lint errors --- webpack/index.d.ts | 67 +++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index 820e76866b..577b96de2f 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -3,9 +3,6 @@ // Definitions by: Qubo , Matt Lewis , Benjamin Lim // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// -/// - import * as UglifyJS from 'uglify-js'; import * as tapable from 'tapable'; @@ -278,14 +275,14 @@ declare namespace webpack { * * @deprecated Replaced by `mainFields` in webpack 2. */ - packageMains?: (string | string[])[]; + packageMains?: Array; /** * Check this field in the package.json for an object. Key-value-pairs are threaded as aliasing according to this spec * * @deprecated Replaced by `aliasFields` in webpack 2. */ - packageAlias?: (string | string[])[]; + packageAlias?: Array; /** * Enable aggressive but unsafe caching for the resolving of a part of your files. @@ -323,9 +320,7 @@ declare namespace webpack { [key: string]: boolean | string; } - interface ExternalsFunctionElement { - (context: any, request: any, callback: (error: any, result: any) => void): any; - } + type ExternalsFunctionElement = (context: any, request: any, callback: (error: any, result: any) => void) => any; interface WatchOptions { /** Delay the rebuilt after the first change. Value is a time in ms. */ @@ -469,7 +464,7 @@ declare namespace webpack { type Rule = LoaderRule | UseRule | RulesRule | OneOfRule; interface Plugin extends tapable.Plugin { - apply (thisArg: Webpack, ...args: any[]): void + apply(thisArg: Webpack, ...args: any[]): void; } interface Webpack { @@ -620,7 +615,7 @@ declare namespace webpack { } interface ContextReplacementPluginStatic { - new (resourceRegExp: any, newContentResource?: any, newContentRecursive?: any, newContentRegExp?: any): Plugin + new (resourceRegExp: any, newContentResource?: any, newContentRecursive?: any, newContentRegExp?: any): Plugin; } interface IgnorePluginStatic { @@ -666,31 +661,31 @@ declare namespace webpack { interface SourceMapDevToolPluginOptions { // output filename pattern (false/null to append) - filename?: string | false | null, + filename?: string | false | null; // source map comment pattern (false to not append) - append?: false | string, + append?: false | string; // template for the module filename inside the source map - moduleFilenameTemplate?: string, + moduleFilenameTemplate?: string; // fallback used when the moduleFilenameTemplate produces a collision - fallbackModuleFilenameTemplate?: string, + fallbackModuleFilenameTemplate?: string; // test/include/exclude files - test?: Condition | Condition[], - include?: Condition | Condition[], - exclude?: Condition | Condition[] + test?: Condition | Condition[]; + include?: Condition | Condition[]; + exclude?: Condition | Condition[]; // whether to include the footer comment with source information - noSources?: boolean, + noSources?: boolean; // the source map sourceRoot ("The URL root from which all sources are relative.") - sourceRoot?: string | null, + sourceRoot?: string | null; // whether to generate per-module source map - module?: boolean, + module?: boolean; // whether to include column information in the source map - columns?: boolean, + columns?: boolean; // whether to preserve line numbers between source and source map lineToLine?: boolean | { - test?: Condition | Condition[], - include?: Condition | Condition[], - exclude?: Condition | Condition[] - } + test?: Condition | Condition[]; + include?: Condition | Condition[]; + exclude?: Condition | Condition[]; + }; } interface EvalSourceMapDevToolPluginStatic { @@ -699,16 +694,16 @@ declare namespace webpack { } interface EvalSourceMapDevToolPluginOptions { - append?: false | string, - moduleFilenameTemplate?: string, - sourceRoot?: string, - module?: boolean, - columns?: boolean, + append?: false | string; + moduleFilenameTemplate?: string; + sourceRoot?: string; + module?: boolean; + columns?: boolean; lineToLine?: boolean | { - test?: Condition | Condition[], - include?: Condition | Condition[], - exclude?: Condition | Condition[] - } + test?: Condition | Condition[]; + include?: Condition | Condition[]; + exclude?: Condition | Condition[]; + }; } interface HotModuleReplacementPluginStatic { @@ -740,7 +735,7 @@ declare namespace webpack { new (): Plugin; } interface LimitChunkCountPluginStatic { - new (options: any): Plugin + new (options: any): Plugin; } interface MinChunkSizePluginStatic { new (options: any): Plugin; @@ -845,7 +840,7 @@ declare namespace webpack { colors?: boolean; } - type CompilerCallback = (err: Error, stats: Stats) => void + type CompilerCallback = (err: Error, stats: Stats) => void; } interface PerformanceOptions { From a1c40dc709822a73dd44b33dc3045fb459d337b9 Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Sun, 15 Jan 2017 23:51:16 +0800 Subject: [PATCH 3/3] chore: disable tslint rules --- webpack/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index 577b96de2f..3ac0cc360f 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -363,6 +363,7 @@ declare namespace webpack { } type ConditionSpec = TestConditionSpec | OrConditionSpec | AndConditionSpec | NotConditionSpec; + // tslint:disable-next-line:no-empty-interface interface ConditionArray extends Array {} type Condition = string | RegExp | ((absPath: string) => boolean) | ConditionSpec | ConditionArray; @@ -623,6 +624,7 @@ declare namespace webpack { } interface PrefetchPluginStatic { + // tslint:disable-next-line:unified-signatures new (context: any, request: any): Plugin; new (request: any): Plugin; }