diff --git a/types/brotli-webpack-plugin/brotli-webpack-plugin-tests.ts b/types/brotli-webpack-plugin/brotli-webpack-plugin-tests.ts new file mode 100644 index 0000000000..d1ee2c369d --- /dev/null +++ b/types/brotli-webpack-plugin/brotli-webpack-plugin-tests.ts @@ -0,0 +1,22 @@ +import * as webpack from 'webpack'; +import BrotliWebpackPlugin = require('brotli-webpack-plugin'); + +new BrotliWebpackPlugin(); // $ExpectType BrotliWebpackPlugin + +const optionsEmpty: BrotliWebpackPlugin.Options = {}; + +const optionsFull: BrotliWebpackPlugin.Options = { + asset: '[path].br[query]', + test: /\.js$/, + threshold: 1024, + minRatio: 0.9, + deleteOriginalAssets: true, +}; + +const config: webpack.Configuration = { + plugins: [ + new BrotliWebpackPlugin(), + new BrotliWebpackPlugin(optionsEmpty), + new BrotliWebpackPlugin(optionsFull), + ] +}; diff --git a/types/brotli-webpack-plugin/index.d.ts b/types/brotli-webpack-plugin/index.d.ts new file mode 100644 index 0000000000..aded1818e5 --- /dev/null +++ b/types/brotli-webpack-plugin/index.d.ts @@ -0,0 +1,44 @@ +// Type definitions for brotli-webpack-plugin 1.1 +// Project: https://github.com/mynameiswhm/brotli-webpack-plugin +// Definitions by: Karol Majewski +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.7 + +import * as webpack from 'webpack'; + +declare class BrotliWebpackPlugin extends webpack.Plugin { + constructor(options?: BrotliWebpackPlugin.Options); +} + +declare namespace BrotliWebpackPlugin { + interface Options { + /** + * The target asset name. Defaults to `'[path].br[query]'`. + * + * - `[file]` is replaced with the original asset file name. + * - `[fileWithoutExt]` is replaced with the file name minus its extension, e.g. the `style` of `style.css`. + * - `[ext]` is replaced with the file name extension, e.g. the `css` of `style.css`. + * - `[path]` is replaced with the path of the original asset. + * - `[query]` is replaced with the query. + */ + asset?: string; + /** + * All assets matching this RegExp are processed. Defaults to every asset. + */ + test?: RegExp; + /** + * Only assets bigger than this size (in bytes) are processed. Defaults to `0`. + */ + threshold?: number; + /** + * Only assets that compress better that this ratio are processed. Defaults to `0.8`. + */ + minRatio?: number; + /** + * Remove original files that were compressed with brotli. Default: `false`. + */ + deleteOriginalAssets?: boolean; + } +} + +export = BrotliWebpackPlugin; diff --git a/types/brotli-webpack-plugin/tsconfig.json b/types/brotli-webpack-plugin/tsconfig.json new file mode 100644 index 0000000000..8a8bf9be39 --- /dev/null +++ b/types/brotli-webpack-plugin/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "brotli-webpack-plugin-tests.ts" + ] +} diff --git a/types/brotli-webpack-plugin/tslint.json b/types/brotli-webpack-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/brotli-webpack-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }