trapcodeio / vite-plugin-ejs

Vite: Use Ejs in your entypoints i.e index.html

Home Page:https://stackblitz.com/edit/vite-plugin-ejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ejs template variable is not working

RyaiStudio opened this issue · comments

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",
}

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.

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.

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

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