feat(webpack-clean): new type definition (#44995)

- definition file for Webpack plugin
- tests

https://github.com/allexcd/webpack-clean
https://github.com/allexcd/webpack-clean#api

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-05-30 01:41:13 +02:00 committed by GitHub
parent 39e59b3186
commit 0d8a27fbbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 105 additions and 0 deletions

43
types/webpack-clean/index.d.ts vendored Normal file
View File

@ -0,0 +1,43 @@
// Type definitions for webpack-clean 1.2
// Project: https://github.com/allexcd/webpack-clean#readme
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { Plugin } from 'webpack';
declare namespace WebpackCleanPlugin {
interface Options {
/**
* directory to be resolved to
* @default null;
*/
basePath?: string | null;
/**
* specify if the .map files should be automatically removed
* @default false
*/
removeMaps?: boolean;
/**
* specify if the files should be force deleted in case of compile errors.
* If forceDelete is not enabled, the compile errors will be logged to stdout but the deletion of the files will not take place
* @default false
*/
forceDelete?: boolean;
}
}
/**
* A webpack plugin to clean specified files after build
*/
declare class WebpackCleanPlugin extends Plugin {
/**
* @param files array of files or string for a single file relative to the basePath
* or to the context of your config (if the basePath param is not specified)
*/
constructor(files: string | string[], options?: WebpackCleanPlugin.Options);
}
/**
* A webpack plugin to clean specified files after build
*/
export = WebpackCleanPlugin;

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",
"webpack-clean-tests.ts"
]
}

View File

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

View File

@ -0,0 +1,38 @@
/// <reference types="node" />
import WebpackCleanPlugin = require('webpack-clean');
import path = require('path');
module.exports = {
context: path.join(__dirname, './'),
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [new WebpackCleanPlugin(['dist/test1.js', 'dist/test2.js'])],
};
module.exports = {
plugins: [new WebpackCleanPlugin('dist/fileA.js', { basePath: path.join(__dirname, './') })],
};
module.exports = {
plugins: [new WebpackCleanPlugin(['fileA.js', 'fileB.js'], { basePath: path.join(__dirname, 'dist') })],
};
module.exports = {
plugins: [
new WebpackCleanPlugin(['fileA.js', 'fileB.js'], { basePath: path.join(__dirname, 'dist'), removeMaps: true }),
],
};
module.exports = {
plugins: [
new WebpackCleanPlugin(['fileA.js', 'fileB.js'], {
basePath: path.join(__dirname, 'dist'),
removeMaps: true,
forceDelete: true,
}),
],
};