Skip to content

Commit

Permalink
types: inline @types/terser-webpack-plugin (#9078)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo authored Mar 31, 2021
1 parent 558227f commit 1be68ca
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/types/config/build.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Options as SassOptions } from 'sass'
import { Options as OptimizeCssAssetsWebpackPluginOptions } from 'optimize-css-assets-webpack-plugin'
import { Plugin as PostcssPlugin } from 'postcss'
import { Options as PugOptions } from 'pug'
import { TerserPluginOptions } from 'terser-webpack-plugin'
import { VueLoaderOptions } from 'vue-loader'
import {
Configuration as WebpackConfiguration,
Expand All @@ -25,6 +24,8 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import { Options as WebpackDevMiddlewareOptions } from 'webpack-dev-middleware'
import { MiddlewareOptions as WebpackHotMiddlewareOptions, ClientOptions as WebpackHotMiddlewareClientOptions } from 'webpack-hot-middleware'

import { TerserPluginOptions } from '../terser-webpack-plugins'

type CssLoaderUrlFunction = (url: string, resourcePath: string) => boolean
type CssLoaderImportFunction = (url: string, media: string, resourcePath: string) => boolean

Expand Down
1 change: 0 additions & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@types/pug": "^2.0.4",
"@types/sass": "^1.16.0",
"@types/serve-static": "^1.13.9",
"@types/terser-webpack-plugin": "^4.2.0",
"@types/webpack": "^4.41.27",
"@types/webpack-bundle-analyzer": "^3.9.2",
"@types/webpack-dev-middleware": "^4.1.2",
Expand Down
115 changes: 115 additions & 0 deletions packages/types/terser-webpack-plugins/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Type definitions for terser-webpack-plugin 4.2
// Project: https://github.com/webpack-contrib/terser-webpack-plugin
// Definitions by: Daniel Schopf <https://github.com/Danscho>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/* eslint-disable */
import { Plugin } from 'webpack';
import { MinifyOptions } from 'terser';

/**
* This plugin uses terser to minify your JavaScript.
*/
declare namespace TerserPlugin {
interface MinifyResult {
map: any;
code: any;
extractedComments: any;
}

interface FileData {
readonly filename: string;
readonly basename: string;
readonly query: string;
readonly hash: string;
}

interface ExtractCommentOptions {
condition: string | RegExp | ExtractCommentFn;
filename?: string | FilenameFn;
banner?: boolean | string | FormatFn;
}

type ExtractCommentFn = (astNode: any, comment: any) => boolean | object;

type FormatFn = (input: string) => string;

type FilenameFn = (fileData: FileData) => string;

interface TerserPluginOptions {
/**
* Test to match files against.
* @default /\.m?js(\?.*)?$/i
*/
test?: string | RegExp | Array<string | RegExp>;

/**
* Files to include.
* @default undefined
*/
include?: string | RegExp | Array<string | RegExp>;

/**
* Files to exclude.
* @default undefined
*/
exclude?: string | RegExp | Array<string | RegExp>;

/**
* ⚠ Ignored in webpack 5! Please use {@link webpack.js.org/configuration/other-options/#cache.}
* Enable/disable file caching.
* Default path to cache directory: `node_modules/.cache/terser-webpack-plugin`.
* @default true
*/
cache?: boolean | string;

/**
* ⚠ Ignored in webpack 5! Please use {@link webpack.js.org/configuration/other-options/#cache}.
* Allows you to override default cache keys.
*/
cacheKeys?: (defaultCacheKeys: any, file: any) => object;

/**
* Enable/disable multi-process parallel running.
* Use multi-process parallel running to improve the build speed. Default number of concurrent runs: os.cpus().length - 1.
* @default true
*/
parallel?: boolean | number;

/**
* Use source maps to map error message locations to modules (this slows down the compilation).
* If you use your own minify function please read the minify section for handling source maps correctly.
* @default false
*/
sourceMap?: boolean;

/**
* Allows you to override default minify function.
* By default plugin uses terser package. Useful for using and testing unpublished versions or forks
* @default undefined
*/
minify?: (file: any, sourceMap: any, minimizerOptions?: MinifyOptions) => MinifyResult;

/**
* Terser minify {@link https://github.com/terser/terser#minify-options|options}.
*/
terserOptions?: MinifyOptions;

/**
* Whether comments shall be extracted to a separate file, (see details).
* By default extract only comments using /^\**!|@preserve|@license|@cc_on/i regexp condition and remove remaining comments.
* If the original file is named foo.js, then the comments will be stored to foo.js.LICENSE.txt.
* The terserOptions.output.comments option specifies whether the comment will be preserved,
* i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted
* @default true
*/
extractComments?: boolean | string | RegExp | ExtractCommentFn | ExtractCommentOptions;
}
}

declare class TerserPlugin extends Plugin {
constructor(opts?: TerserPlugin.TerserPluginOptions);
}

export = TerserPlugin;
30 changes: 11 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2648,14 +2648,6 @@
resolved "https://registry.npmjs.org/@types/tapable/-/tapable-1.0.7.tgz#545158342f949e8fd3bfd813224971ecddc3fac4"
integrity sha512-0VBprVqfgFD7Ehb2vd8Lh9TG3jP98gvr8rgehQqzztZNI7o8zS8Ad4jyZneKELphpuE212D8J70LnSNQSyO6bQ==

"@types/terser-webpack-plugin@^4.2.0":
version "4.2.0"
resolved "https://registry.npmjs.org/@types/terser-webpack-plugin/-/terser-webpack-plugin-4.2.0.tgz#fe39917d334287c5cf25abcf370867a31ed59cd6"
integrity sha512-oGfGZzjwKY7s8gAYLZJuVuu9GXuc/ACo7bL/DQg7ROFkEMFQULB1W7qZjQrTXf2SkTfQx7/zcerfuLkUCVFGhg==
dependencies:
"@types/webpack" "*"
terser "^4.6.13"

"@types/uglify-js@*":
version "3.13.0"
resolved "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-3.13.0.tgz#1cad8df1fb0b143c5aba08de5712ea9d1ff71124"
Expand Down Expand Up @@ -2695,26 +2687,26 @@
"@types/source-list-map" "*"
source-map "^0.7.3"

"@types/webpack@*", "@types/webpack@^4.41.8":
version "4.41.26"
resolved "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.26.tgz#27a30d7d531e16489f9c7607c747be6bc1a459ef"
integrity sha512-7ZyTfxjCRwexh+EJFwRUM+CDB2XvgHl4vfuqf1ZKrgGvcS5BrNvPQqJh3tsZ0P6h6Aa1qClVHaJZszLPzpqHeA==
"@types/webpack@^4", "@types/webpack@^4.41.27":
version "4.41.27"
resolved "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.27.tgz#f47da488c8037e7f1b2dbf2714fbbacb61ec0ffc"
integrity sha512-wK/oi5gcHi72VMTbOaQ70VcDxSQ1uX8S2tukBK9ARuGXrYM/+u4ou73roc7trXDNmCxCoerE8zruQqX/wuHszA==
dependencies:
"@types/anymatch" "*"
"@types/node" "*"
"@types/tapable" "*"
"@types/tapable" "^1"
"@types/uglify-js" "*"
"@types/webpack-sources" "*"
source-map "^0.6.0"

"@types/webpack@^4", "@types/webpack@^4.41.27":
version "4.41.27"
resolved "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.27.tgz#f47da488c8037e7f1b2dbf2714fbbacb61ec0ffc"
integrity sha512-wK/oi5gcHi72VMTbOaQ70VcDxSQ1uX8S2tukBK9ARuGXrYM/+u4ou73roc7trXDNmCxCoerE8zruQqX/wuHszA==
"@types/webpack@^4.41.8":
version "4.41.26"
resolved "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.26.tgz#27a30d7d531e16489f9c7607c747be6bc1a459ef"
integrity sha512-7ZyTfxjCRwexh+EJFwRUM+CDB2XvgHl4vfuqf1ZKrgGvcS5BrNvPQqJh3tsZ0P6h6Aa1qClVHaJZszLPzpqHeA==
dependencies:
"@types/anymatch" "*"
"@types/node" "*"
"@types/tapable" "^1"
"@types/tapable" "*"
"@types/uglify-js" "*"
"@types/webpack-sources" "*"
source-map "^0.6.0"
Expand Down Expand Up @@ -12757,7 +12749,7 @@ terser-webpack-plugin@^4.2.3:
terser "^5.3.4"
webpack-sources "^1.4.3"

terser@^4.1.2, terser@^4.6.13, terser@^4.6.3:
terser@^4.1.2, terser@^4.6.3:
version "4.8.0"
resolved "https://registry.npmjs.org/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17"
integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==
Expand Down

0 comments on commit 1be68ca

Please sign in to comment.