Skip to content

Commit 2abf012

Browse files
committed
feat: add support for custom Terser options
1 parent 222592e commit 2abf012

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ json
6868
css
6969
wasm
7070
visualizer
71+
terser (considered by default in production)
7172
```
7273

7374
You can pass an input plugin with their supported option:

src/main.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ export type Plugin =
2424
| "babel"
2525
| "wasm"
2626
| "as"
27+
| "terser"
2728
| ["ts", typeof typescript]
2829
| ["babel", typeof babel]
2930
| ["coffee", typeof coffeescript]
3031
| ["json", typeof json]
3132
| ["css", typeof cssOnly]
3233
| ["wasm", typeof wasm]
3334
| ["as", typeof asc]
35+
| ["terser", typeof terser]
3436

3537
// function to check if the first array has any of the second array
3638
// first array can have `[string, object]` as their input
@@ -239,22 +241,34 @@ export function createPlugins(
239241

240242
plugins.push(...pluginsCommon)
241243

242-
// minify only in production mode
244+
// Replace in production mode
243245
if (process.env.NODE_ENV === "production") {
244-
plugins.push(...[
246+
plugins.push(
245247
// set NODE_ENV to production
246248
replace({
247249
'process.env.NODE_ENV':JSON.stringify('production'),
248250
}),
249-
// minify
250-
terser({
251-
ecma: 2018,
252-
warnings: true,
253-
compress: {
254-
drop_console: false,
255-
},
256-
}),
257-
])
251+
)
252+
}
253+
254+
// terser
255+
const terserIndex = includesAny(inputPluginsNames, ["terser"])
256+
if (terserIndex !== null && typeof inputPluginsNames[terserIndex] === "string") {
257+
// plugin with options
258+
plugins.push(terser(inputPluginsNames[terserIndex][1]))
259+
} else {
260+
if (process.env.NODE_ENV === "production") {
261+
plugins.push(
262+
// minify
263+
terser({
264+
ecma: 2018,
265+
warnings: true,
266+
compress: {
267+
drop_console: false,
268+
},
269+
}),
270+
)
271+
}
258272
}
259273

260274
return plugins

0 commit comments

Comments
 (0)