@@ -33,6 +33,9 @@ type RollupAscOptions = Parameters<typeof asc>[0] & Record<string, any>
3333import type visualizer from "rollup-plugin-visualizer"
3434type RollupVisualizerOptions = Parameters < typeof visualizer > [ 0 ]
3535
36+ import { existsSync } from "fs"
37+ import { join } from "path"
38+
3639export type Plugin =
3740 | "js"
3841 | "ts"
@@ -68,6 +71,8 @@ export function createPlugins(
6871 inputPluginsNames : Array < Plugin > = [ "ts" , "js" , "json" , "coffee" ] ,
6972 extraPlugins ?: Array < any >
7073) {
74+ const configDir = require . main ?. filename ?. replace ( / n o d e _ m o d u l e s .* / , "" )
75+
7176 let plugins = [ ]
7277
7378 // language specific
@@ -188,9 +193,7 @@ export function createPlugins(
188193 )
189194
190195 // terser
191- pushPlugin (
192- [ "terser" ] ,
193- [ "rollup-plugin-terser" , "terser" ] ,
196+ let terserOptions = (
194197 process . env . NODE_ENV === "production"
195198 ? {
196199 ecma : 2018 ,
@@ -202,9 +205,22 @@ export function createPlugins(
202205 comments : false ,
203206 } ,
204207 }
205- : { } ,
206- process . env . NODE_ENV === "production"
207- )
208+ : { }
209+ ) as RollupTerserOptions
210+ if ( typeof configDir === "string" ) {
211+ const terserConfigFile = join ( configDir , ".terserrc.js" )
212+ if ( existsSync ( terserConfigFile ) ) {
213+ const loadedTerserConfigFile = require ( terserConfigFile ) as { default : RollupTerserOptions } | RollupTerserOptions
214+ if ( loadedTerserConfigFile !== undefined ) {
215+ if ( "default" in loadedTerserConfigFile ) {
216+ terserOptions = loadedTerserConfigFile . default
217+ } else {
218+ terserOptions = loadedTerserConfigFile
219+ }
220+ }
221+ }
222+ }
223+ pushPlugin ( [ "terser" ] , [ "rollup-plugin-terser" , "terser" ] , terserOptions , process . env . NODE_ENV === "production" )
208224
209225 // utility function that pushes a plugin
210226 function pushPlugin (
0 commit comments