Skip to content

Commit

Permalink
feat: added built-in typescript types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Aug 26, 2021
1 parent c946d50 commit 0a7cc94
Show file tree
Hide file tree
Showing 16 changed files with 839 additions and 341 deletions.
53 changes: 50 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Using supported `devtool` values enable source map generation.
| :---------------------------------------: | :-----------------------------------------------------------------------------: | :-------------------------------------------------------------: | :--------------------------------------------------------------------------- |
| **[`test`](#test)** | `String\|RegExp\|Array<String\|RegExp>` | `/\.m?js(\?.*)?$/i` | Test to match files against. |
| **[`include`](#include)** | `String\|RegExp\|Array<String\|RegExp>` | `undefined` | Files to include. |
| **[`exclude`](#)** | `String\|RegExp\|Array<String\|RegExp>` | `undefined` | Files to exclude. |
| **[`exclude`](#exclude)** | `String\|RegExp\|Array<String\|RegExp>` | `undefined` | Files to exclude. |
| **[`parallel`](#parallel)** | `Boolean\|Number` | `true` | Use multi-process parallel running to improve the build speed. |
| **[`minify`](#minify)** | `Function` | `undefined` | Allows you to override default minify function. |
| **[`minify`](#minify)** | `Function` | `TerserPlugin.terserMinify` | Allows you to override default minify function. |
| **[`terserOptions`](#terseroptions)** | `Object` | [`default`](https://github.com/terser-js/terser#minify-options) | Terser [minify options](https://github.com/terser-js/terser#minify-options). |
| **[`extractComments`](#extractcomments)** | `Boolean\|String\|RegExp\|Function<(node, comment) -> Boolean\|Object>\|Object` | `true` | Whether comments shall be extracted to a separate file. |

Expand Down Expand Up @@ -185,7 +185,7 @@ module.exports = {
### `minify`

Type: `Function`
Default: `undefined`
Default: `TerserPlugin.terserMinify`

Allows you to override default minify function.
By default plugin uses [terser](https://github.com/terser-js/terser) package.
Expand Down Expand Up @@ -637,6 +637,53 @@ module.exports = {
};
```

### Typescript

With default terser minify function:

```ts
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: true,
},
}),
],
},
};
```

With built-in minify functions:

```ts
import type { SwcMinifyFunction } from "terser-webpack-plugin";

module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin<SwcMinifyFunction>({
minify: TerserPlugin.swcMinify,
terserOptions: {
compress: true,
},
}),

// Alternative:
new TerserPlugin<typeof TerserPlugin.swcMinify>({
minify: TerserPlugin.swcMinify,
terserOptions: {
compress: true,
},
}),
],
},
};
```

## Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.
Expand Down
Loading

0 comments on commit 0a7cc94

Please sign in to comment.