- Notifications
You must be signed in to change notification settings - Fork5
Vite: Use Ejs in your entypoints i.e index.html
NotificationsYou must be signed in to change notification settings
trapcodeio/vite-plugin-ejs
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Useejs template language in your entrypoint i.eindex.html
Note: For Vite version <5 usev1.6.4 of this plugin.
npm i vite-plugin-ejs# oryarn add vite-plugin-ejsFile:vite.config.js
import{defineConfig}from"vite";import{ViteEjsPlugin}from"vite-plugin-ejs";exportdefaultdefineConfig({plugins:[// Without DataViteEjsPlugin(),// With DataViteEjsPlugin({domain:"example.com",title:"My vue project!"}),// Or With Vite ConfigViteEjsPlugin((viteConfig)=>{// viteConfig is the current viteResolved config.return{root:viteConfig.root,domain:"example.com",title:"My vue project!"}}),],});
File:index.html
<!DOCTYPE html><htmllang="en"><head> <metacharset="UTF-8"/> <linkrel="icon"href="/favicon.ico"/> <metaname="viewport"content="width=device-width, initial-scale=1.0"/> <title><%= domain%> |<%= title%></title><!-- Run Conditions--><%if(isDev){%><script src="/path/to/development-only-script.js"></script><% }else {%><script src="/path/to/production-only-script.js" crossorigin="anonymous"></script><% }%></head><body><divid="app"></div><scripttype="module"src="/src/main.ts"></script></body></html>
Note:isDev is included in your data by default
The object below is the default data of the render function.
return{NODE_ENV:config.mode,isDev:config.mode==="development"}
You can configure ejs by passing an object to the plugin.
exportdefaultdefineConfig({plugins:[ViteEjsPlugin({title:'My vue project!'},{ejs:{// ejs options goes here.beautify:true,},}),],});
If you want to useviteconfig to configure ejs, you can pass a function to the plugin, the function will receive thecurrent vite config as the first argument.
exportdefaultdefineConfig({plugins:[ViteEjsPlugin({title:'My vue project!'},{ejs:(viteConfig)=>({// ejs options goes here.views:[viteConfig.publicDir]})}),],});
About
Vite: Use Ejs in your entypoints i.e index.html
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.