Skip to content

Commit 7196d68

Browse files
committed
feat: support custom options for replace
1 parent 5391244 commit 7196d68

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ css
6969
wasm
7070
visualizer
7171
terser (considered by default in production)
72+
replace (considered by default in production)
7273
```
7374

7475
You can pass an input plugin with their supported option:

src/main.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type Plugin =
2525
| "wasm"
2626
| "as"
2727
| "terser"
28+
| "replace"
2829
| ["ts", typeof typescript]
2930
| ["babel", typeof babel]
3031
| ["coffee", typeof coffeescript]
@@ -33,6 +34,7 @@ export type Plugin =
3334
| ["wasm", typeof wasm]
3435
| ["as", typeof asc]
3536
| ["terser", typeof terser]
37+
| ["replace", typeof replace]
3638

3739
// function to check if the first array has any of the second array
3840
// first array can have `[string, object]` as their input
@@ -241,14 +243,20 @@ export function createPlugins(
241243

242244
plugins.push(...pluginsCommon)
243245

244-
// Replace in production mode
245-
if (process.env.NODE_ENV === "production") {
246-
plugins.push(
247-
// set NODE_ENV to production
248-
replace({
249-
'process.env.NODE_ENV':JSON.stringify('production'),
250-
}),
251-
)
246+
// replace
247+
const replaceIndex = includesAny(inputPluginsNames, ["replace"])
248+
if (replaceIndex !== null && typeof inputPluginsNames[replaceIndex] === "string") {
249+
// plugin with options
250+
plugins.push(replace(inputPluginsNames[replaceIndex][1]))
251+
} else {
252+
if (process.env.NODE_ENV === "production") {
253+
plugins.push(
254+
// set NODE_ENV to production
255+
replace({
256+
'process.env.NODE_ENV':JSON.stringify('production'),
257+
}),
258+
)
259+
}
252260
}
253261

254262
// terser

0 commit comments

Comments
 (0)