1- import { includesAny , getPluginFunction } from "./utils"
1+ import { includesAny , getPluginFunction , loadConfigFile } from "./utils"
22
33import type resolve from "@rollup/plugin-node-resolve"
44type RollupResolveOptions = Parameters < typeof resolve > [ 0 ]
@@ -68,6 +68,8 @@ export function createPlugins(
6868 inputPluginsNames : Array < Plugin > = [ "ts" , "js" , "json" , "coffee" ] ,
6969 extraPlugins ?: Array < any >
7070) {
71+ const configDir = require . main ?. filename ?. replace ( / n o d e _ m o d u l e s .* / , "" )
72+
7173 let plugins = [ ]
7274
7375 // language specific
@@ -188,9 +190,7 @@ export function createPlugins(
188190 )
189191
190192 // terser
191- pushPlugin (
192- [ "terser" ] ,
193- [ "rollup-plugin-terser" , "terser" ] ,
193+ let terserOptions = (
194194 process . env . NODE_ENV === "production"
195195 ? {
196196 ecma : 2018 ,
@@ -202,9 +202,15 @@ export function createPlugins(
202202 comments : false ,
203203 } ,
204204 }
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" )
208214
209215 // utility function that pushes a plugin
210216 function pushPlugin (
0 commit comments