A Vite plugin to seamlessly use Eta templating engine in your project entry point.
npm install @rinoshiyo/vite-plugin-etaUse Eta template language in your entrypoint i.e index.html
Compatibility Note: This plugin requires Vite v5 or newer.
- Installation
- Usage
- Default Data
- Configure Eta
``sh`
npm i @rinoshiyo/vite-plugin-etaor
yarn add @rinoshiyo/vite-plugin-eta
File: vite.config.js
`javascript
import {defineConfig} from "vite";
import {ViteEtaPlugin} from "@rinoshiyo/vite-plugin-eta";
export default defineConfig({
plugins: [
// Without Data
ViteEtaPlugin(),
// With Data
ViteEtaPlugin({
domain: "example.com",
title: "My vue project!"
}),
// Or With Vite Config
ViteEtaPlugin((viteConfig) => {
// viteConfig is the current viteResolved config.
return {
root: viteConfig.root,
domain: "example.com",
title: "My vue project!"
}
}),
],
});
`
File: index.html
`ejs
<% if(isDev){ %>
<% } else { %>
<% } %>
Note:
isDev is included in your data by default$3
The object below is the default data of the render function.
`javascript
return {
NODE_ENV: config.mode,
isDev: config.mode === "development"
}
`$3
You can configure Eta by passing an object to the plugin.
`js
export default defineConfig({
plugins: [
ViteEtaPlugin(
{title: 'My vue project!'},
{
eta: {
// Eta options goes here.
cache: false
},
}
),
],
});
`If you want to use
viteconfig to configure Eta, you can pass a function to the plugin, the function will receive the current vite config as the first argument.`js
export default defineConfig({
plugins: [
ViteEtaPlugin(
{title: 'My vue project!'},
{
eta: (viteConfig) => ({
// Eta options goes here.
views: viteConfig.publicDir
})
}
),
],
});
`---
🧡 Acknowledgements
vite-plugin-eta created by moyui默羽. I extend my sincere thanks to the original author for creating and maintaining the initial project.Furthermore, the structure and documentation of this plugin were heavily inspired by the excellent work done on
vite-plugin-ejs` by trapcodeio.