From 2fc13d9e70be882fcfbffc203fcc09ba0551ca25 Mon Sep 17 00:00:00 2001 From: Michael Strobel Date: Wed, 9 Aug 2017 05:17:49 +0800 Subject: [PATCH] [webpack-bunde-analyzer] Add type definitions (#18651) --- types/webpack-bundle-analyzer/index.d.ts | 80 +++++++++++++++++++ types/webpack-bundle-analyzer/tsconfig.json | 22 +++++ types/webpack-bundle-analyzer/tslint.json | 1 + .../webpack-bundle-analyzer-tests.ts | 25 ++++++ 4 files changed, 128 insertions(+) create mode 100644 types/webpack-bundle-analyzer/index.d.ts create mode 100644 types/webpack-bundle-analyzer/tsconfig.json create mode 100644 types/webpack-bundle-analyzer/tslint.json create mode 100644 types/webpack-bundle-analyzer/webpack-bundle-analyzer-tests.ts diff --git a/types/webpack-bundle-analyzer/index.d.ts b/types/webpack-bundle-analyzer/index.d.ts new file mode 100644 index 0000000000..c563a9e3cf --- /dev/null +++ b/types/webpack-bundle-analyzer/index.d.ts @@ -0,0 +1,80 @@ +// Type definitions for webpack-bundle-analyzer 2.9 +// Project: https://github.com/th0r/webpack-bundle-analyzer +// Definitions by: Michael Strobel +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as webpack from 'webpack'; + +export namespace BundleAnalyzerPlugin { + interface Options { + /** + * Can be "server", "static" or "disabled". + * Defaults to "server". + * In "server" mode analyzer will start HTTP server to show bundle report. + * In "static" mode single HTML file with bundle report will be generated. + * In "disabled" mode you can use this plugin to just generate Webpack Stats JSON file by setting "generateStatsFile" to true. + */ + analyzerMode?: 'server' | 'static' | 'disabled'; + + /** + * Host that will be used in `server` mode to start HTTP server. + * Defaults to 127.0.0.1 + */ + analyzerHost?: string; + + /** + * Port that will be used in `server` mode to start HTTP server. + * Defaults to 8888 + */ + analyzerPort?: number; + + /** + * Path to bundle report file that will be generated in "static" mode. + * Relative to bundles output directory. + * Defaults to "report.html" + */ + reportFilename?: string; + + /** + * Module sizes to show in report by default. + * Should be one of "stat", "parsed" or "gzip". + * Defaults to "parsed" + */ + defaultSizes?: 'parsed' | 'stat' | 'gzip'; + + /** + * Automatically open report in default browser. + * Defaults to true + */ + openAnalyzer?: boolean; + + /** + * If true, Webpack Stats JSON file will be generated in bundles output directory. + * Defaults to false + */ + generateStatsFile?: boolean; + + /** + * Name of Webpack Stats JSON file that will be generated if generateStatsFile is true. + * Relative to bundles output directory. + * Defaults to "stats.json" + */ + statsFilename?: string; + + /** + * Options for stats.toJson() method. + * For example you can exclude sources of your modules from stats file with "source: false" option. + */ + statsOptions?: null | webpack.Stats.ToJsonOptionsObject; + + /** + * Log level. Can be "info", "warn", "error" or "silent". + * Defaults to "info" + */ + logLevel?: 'info' | 'warn' | 'error' | 'silent'; + } +} + +export class BundleAnalyzerPlugin extends webpack.Plugin { + constructor(options?: BundleAnalyzerPlugin.Options); +} diff --git a/types/webpack-bundle-analyzer/tsconfig.json b/types/webpack-bundle-analyzer/tsconfig.json new file mode 100644 index 0000000000..257de048ef --- /dev/null +++ b/types/webpack-bundle-analyzer/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "webpack-bundle-analyzer-tests.ts" + ] +} diff --git a/types/webpack-bundle-analyzer/tslint.json b/types/webpack-bundle-analyzer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/webpack-bundle-analyzer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/webpack-bundle-analyzer/webpack-bundle-analyzer-tests.ts b/types/webpack-bundle-analyzer/webpack-bundle-analyzer-tests.ts new file mode 100644 index 0000000000..0b5fcabcc7 --- /dev/null +++ b/types/webpack-bundle-analyzer/webpack-bundle-analyzer-tests.ts @@ -0,0 +1,25 @@ +import * as webpack from 'webpack'; +import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; + +const config: webpack.Configuration = { + plugins: [ + new BundleAnalyzerPlugin(), + new BundleAnalyzerPlugin({ + analyzerMode: 'static' + }), + new BundleAnalyzerPlugin({ + analyzerMode: 'server', + analyzerHost: '127.0.0.1', + analyzerPort: 8888, + reportFilename: 'report.html', + defaultSizes: 'parsed', + openAnalyzer: true, + generateStatsFile: true, + statsFilename: 'stats.json', + statsOptions: { + source: false + }, + logLevel: 'info' + }) + ] +};