1
- import { includesAny , getPluginFunction } from "./utils"
1
+ import { includesAny , getPluginFunction , loadConfigFile } from "./utils"
2
2
3
3
import type resolve from "@rollup/plugin-node-resolve"
4
4
type RollupResolveOptions = Parameters < typeof resolve > [ 0 ]
@@ -68,6 +68,8 @@ export function createPlugins(
68
68
inputPluginsNames : Array < Plugin > = [ "ts" , "js" , "json" , "coffee" ] ,
69
69
extraPlugins ?: Array < any >
70
70
) {
71
+ const configDir = require . main ?. filename ?. replace ( / n o d e _ m o d u l e s .* / , "" )
72
+
71
73
let plugins = [ ]
72
74
73
75
// language specific
@@ -188,9 +190,7 @@ export function createPlugins(
188
190
)
189
191
190
192
// terser
191
- pushPlugin (
192
- [ "terser" ] ,
193
- [ "rollup-plugin-terser" , "terser" ] ,
193
+ let terserOptions = (
194
194
process . env . NODE_ENV === "production"
195
195
? {
196
196
ecma : 2018 ,
@@ -202,9 +202,15 @@ export function createPlugins(
202
202
comments : false ,
203
203
} ,
204
204
}
205
- : { } ,
206
- process . env . NODE_ENV === "production"
207
- )
205
+ : { }
206
+ ) as RollupTerserOptions
207
+ if ( typeof configDir === "string" ) {
208
+ const maybeConfig = loadConfigFile ( configDir , [ ".terserrc.js" , ".terserrc" ] )
209
+ if ( maybeConfig !== null ) {
210
+ terserOptions = maybeConfig as RollupTerserOptions
211
+ }
212
+ }
213
+ pushPlugin ( [ "terser" ] , [ "rollup-plugin-terser" , "terser" ] , terserOptions , process . env . NODE_ENV === "production" )
208
214
209
215
// utility function that pushes a plugin
210
216
function pushPlugin (
0 commit comments