Skip to content

Commit 9e9e122

Browse files
committed
fix: set preventAssignment to remove the warning from the replace plugin
Fixes #63
1 parent 8cb2853 commit 9e9e122

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/main.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type RollupAscOptions = Parameters<typeof asc>[0] & Record<string, any>
3333
import type visualizer from "rollup-plugin-visualizer"
3434
type RollupVisualizerOptions = Parameters<typeof visualizer>[0]
3535

36+
import { existsSync } from "fs"
37+
import { join } from "path"
38+
3639
export 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(/node_modules.*/, "")
75+
7176
let plugins = []
7277

7378
// language specific
@@ -182,14 +187,13 @@ export function createPlugins(
182187
["@rollup/plugin-replace"],
183188
{
184189
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
190+
preventAssignment: true,
185191
},
186192
true
187193
)
188194

189195
// terser
190-
pushPlugin(
191-
["terser"],
192-
["rollup-plugin-terser", "terser"],
196+
let terserOptions = (
193197
process.env.NODE_ENV === "production"
194198
? {
195199
ecma: 2018,
@@ -201,9 +205,23 @@ export function createPlugins(
201205
comments: false,
202206
},
203207
}
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")
207225

208226
// utility function that pushes a plugin
209227
function pushPlugin(

0 commit comments

Comments
 (0)