trapcodeio / vite-plugin-ejs

Vite: Use Ejs in your entypoints i.e index.html
https://stackblitz.com/edit/vite-plugin-ejs
66 stars 5 forks source link

ejs template variable is not working #3

Closed RyaiStudio closed 2 years ago

RyaiStudio commented 2 years ago

variable is undefined vite ejs plugin

test.config.js

Screen Shot 2022-05-25 at 7 43 24 PM

vite.html

<head>
  <meta charset="UTF-8" />
  <link rel="icon" href="/favicon.ico" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title><%= title %></title>
</head>

now I'm getting error

 ERROR  7:41:32 PM [vite] Internal server error: ejs:7                                                     
    5|     <link rel="icon" href="/favicon.ico" />
    6|     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    7|     <title><%= title %></title>
    8|   </head>
    9|   <body>
   10|     <div id="app"></div>

title is not defined

node: v16.15.0

{ 
 "vite": "^2.9.5",
 "vite-plugin-ejs": "^1.4.4",
 "vue": "^3.2.34",
}
trapcodeio commented 2 years ago

I have re-tested this package and it works as expected. Here is a StackBlitz Link

https://stackblitz.com/edit/vite-plugin-ejs?file=index.html

Open the preview in a new window and you should see the page title is set to My vue project! without errors

Looking at your test.config.js file, I see that you are merging with lodash I guess this may be the reason.

Do let me know if you get it resolved.

RyaiStudio commented 2 years ago

I think the reason is that vite-plugin-html does not work together. I try to remove the other plugin and it works perfectly fine.

vite-plugin-html has same functionality on inject data maybe that why.

trapcodeio commented 2 years ago

Try registering VitePluginEjs at the end.. after vite-plugin-html

trapcodeio commented 2 years ago

Did this work out? I would like to close this issue if you have resolved it.