|
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] |
@@ -33,9 +33,6 @@ 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 | | - |
39 | 36 | export type Plugin = |
40 | 37 | | "js" |
41 | 38 | | "ts" |
@@ -208,16 +205,9 @@ export function createPlugins( |
208 | 205 | : {} |
209 | 206 | ) as RollupTerserOptions |
210 | 207 | 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 | | - } |
| 208 | + const maybeConfig = loadConfigFile(configDir, [".terserrc.js", ".terserrc"]) |
| 209 | + if (maybeConfig !== null) { |
| 210 | + terserOptions = maybeConfig as RollupTerserOptions |
221 | 211 | } |
222 | 212 | } |
223 | 213 | pushPlugin(["terser"], ["rollup-plugin-terser", "terser"], terserOptions, process.env.NODE_ENV === "production") |
|
0 commit comments