@@ -33,6 +33,9 @@ type RollupAscOptions = Parameters<typeof asc>[0] & Record<string, any>
33
33
import type visualizer from "rollup-plugin-visualizer"
34
34
type RollupVisualizerOptions = Parameters < typeof visualizer > [ 0 ]
35
35
36
+ import { existsSync } from "fs"
37
+ import { join } from "path"
38
+
36
39
export type Plugin =
37
40
| "js"
38
41
| "ts"
@@ -68,6 +71,8 @@ export function createPlugins(
68
71
inputPluginsNames : Array < Plugin > = [ "ts" , "js" , "json" , "coffee" ] ,
69
72
extraPlugins ?: Array < any >
70
73
) {
74
+ const configDir = require . main ?. filename ?. replace ( / n o d e _ m o d u l e s .* / , "" )
75
+
71
76
let plugins = [ ]
72
77
73
78
// language specific
@@ -182,14 +187,13 @@ export function createPlugins(
182
187
[ "@rollup/plugin-replace" ] ,
183
188
{
184
189
"process.env.NODE_ENV" : JSON . stringify ( process . env . NODE_ENV ) ,
190
+ preventAssignment : true ,
185
191
} ,
186
192
true
187
193
)
188
194
189
195
// terser
190
- pushPlugin (
191
- [ "terser" ] ,
192
- [ "rollup-plugin-terser" , "terser" ] ,
196
+ let terserOptions = (
193
197
process . env . NODE_ENV === "production"
194
198
? {
195
199
ecma : 2018 ,
@@ -201,9 +205,23 @@ export function createPlugins(
201
205
comments : false ,
202
206
} ,
203
207
}
204
- : { } ,
205
- process . env . NODE_ENV === "production"
206
- )
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
+ console . log ( terserOptions )
224
+ pushPlugin ( [ "terser" ] , [ "rollup-plugin-terser" , "terser" ] , terserOptions , process . env . NODE_ENV === "production" )
207
225
208
226
// utility function that pushes a plugin
209
227
function pushPlugin (
0 commit comments