File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6868css
6969wasm
7070visualizer
71+ terser (considered by default in production)
7172```
7273
7374You can pass an input plugin with their supported option:
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments