[webpack-deadcode-plugin]: New definition (#46260)

This commit is contained in:
inglec-arista 2020-07-22 20:11:31 +01:00 committed by GitHub
parent 732fcd7f7c
commit 52391b452d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,38 @@
// Type definitions for webpack-deadcode-plugin 0.1
// Project: https://github.com/MQuy/webpack-deadcode-plugin#readme
// Definitions by: Ciarán Ingle <https://github.com/inglec-arista>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { compilation, Plugin } from 'webpack';
interface Options {
/** Current working directoy for patterns above. If you don't set explicitly, your webpack context will be used. */
context?: string;
/** Whether to run unsed export detection or not. */
detectUnusedExport?: boolean;
/** Whether to run unused files detection or not. */
detectUnusedFiles?: boolean;
/** The array of patterns to not look at. */
exclude?: string[];
/**
* Deadcode does not interrupt the compilation by default.
* If you want to cancel the compilation, set it `true`, it throws a fatal error and stops the compilation.
*/
failOnHint?: boolean;
outputFile?: string;
/**
* The array of patterns to look for unused files and unused export in used files.
* Directly passed to [`fast-glob`](https://github.com/mrmlnc/fast-glob).
*/
patterns?: string[];
}
declare class WebpackDeadcodePlugin extends Plugin {
options: Options;
constructor(options?: Options);
handleAfterEmit(options: Required<Options>, compilation: compilation.Compilation, callback: () => void): void;
}
export = WebpackDeadcodePlugin;

View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"baseUrl": "../",
"forceConsistentCasingInFileNames": true,
"lib": ["es6"],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"typeRoots": ["../"],
"types": []
},
"files": [
"index.d.ts",
"webpack-deadcode-plugin-tests.ts"
]
}

View File

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

View File

@ -0,0 +1,22 @@
import { Configuration, Plugin } from 'webpack';
import DeadCodePlugin = require('webpack-deadcode-plugin');
const webpackConfig: Configuration = {
plugins: [
new DeadCodePlugin({
patterns: ['src/**/*.(js|jsx|css)'],
exclude: ['**/*.(stories|spec).(js|jsx)'],
}),
],
};
const plugin1: Plugin = new DeadCodePlugin();
const plugin2: Plugin = new DeadCodePlugin({});
const plugin3: Plugin = new DeadCodePlugin({
patterns: ['src/**/*.(js|jsx|css)'],
exclude: ['**/*.(stories|spec).(js|jsx)'],
context: '~/foo/bar',
detectUnusedExport: false,
detectUnusedFiles: false,
failOnHint: true,
});