1- import { Plugin } from "vite" ;
1+ import { Plugin , ResolvedConfig } from "vite" ;
22import ejs from "ejs" ;
33
44// ShortHand for EjsOptions or Undefined
55type EjsRenderOptions = ( ejs . Options & { async : false } ) | undefined ;
6- type ViteEjsPluginDataType = Record < string , any > | ( ( ... args : any [ ] ) => Record < string , any > ) ;
6+ type ViteEjsPluginDataType = Record < string , any > | ( ( config : ResolvedConfig ) => Record < string , any > ) ;
77type ViteEjsPluginOptions = { ejs : EjsRenderOptions } ;
88/**
99 * Vite Ejs Plugin Function
@@ -17,9 +17,16 @@ type ViteEjsPluginOptions = {ejs: EjsRenderOptions};
1717 * });
1818 */
1919function ViteEjsPlugin ( data : ViteEjsPluginDataType = { } , options ?: ViteEjsPluginOptions ) : Plugin {
20+ let config : ResolvedConfig ;
21+
2022 return {
2123 name : "vite-plugin-ejs" ,
2224
25+ // Get Resolved config
26+ configResolved ( resolvedConfig ) {
27+ config = resolvedConfig ;
28+ } ,
29+
2330 /**
2431 * Force full reload on .html change
2532 */
@@ -35,13 +42,13 @@ function ViteEjsPlugin(data: ViteEjsPluginDataType = {}, options?: ViteEjsPlugin
3542 enforce : "pre" ,
3643 transform ( html ) {
3744 try {
38- if ( typeof data === "function" ) data = data ( ) ;
45+ if ( typeof data === "function" ) data = data ( config ) ;
3946
4047 html = ejs . render (
4148 html ,
4249 {
43- NODE_ENV : process . env . NODE_ENV ,
44- isDev : process . env . NODE_ENV === "development" ,
50+ NODE_ENV : config . mode ,
51+ isDev : config . mode === "development" ,
4552 ...data
4653 } ,
4754 options ?. ejs
0 commit comments