Add definition for brotli-webpack-plugin (#42009)

This commit is contained in:
Karol Majewski 2020-02-01 00:03:37 +01:00 committed by GitHub
parent d02802bd23
commit df90a9baed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 0 deletions

View File

@ -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),
]
};

44
types/brotli-webpack-plugin/index.d.ts vendored Normal file
View File

@ -0,0 +1,44 @@
// Type definitions for brotli-webpack-plugin 1.1
// Project: https://github.com/mynameiswhm/brotli-webpack-plugin
// Definitions by: Karol Majewski <https://github.com/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;

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }