@@ -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