Skip to content

Latest commit

 

History

History
134 lines (100 loc) · 2.03 KB

README.md

File metadata and controls

134 lines (100 loc) · 2.03 KB

unplugin-eta3

NPM version

Plugin to precompile Eta functions, making it possible to be used in serverless context like Cloudflare Workers.

Install

npm i --save-dev unplugin-eta3
Vite
// vite.config.ts
import eta from "unplugin-eta3/vite";

export default defineConfig({
  plugins: [
    eta({ /* options */ }),
  ],
});

Example: playground/


Rollup
// rollup.config.js
import eta from "unplugin-eta3/rollup";

export default {
  plugins: [
    eta({ /* options */ }),
  ],
};


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require("unplugin-eta3/webpack")({ /* options */ })
  ]
};


Nuxt
// nuxt.config.js
export default defineNuxtConfig({
  modules: [
    ["unplugin-eta3/nuxt", { /* options */ }],
  ],
});

This module works for both Nuxt 2 and Nuxt Vite


Vue CLI
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require("unplugin-eta3/webpack")({ /* options */ }),
    ],
  },
};


esbuild
// esbuild.config.js
import { build } from "esbuild";
import eta from "unplugin-eta3/esbuild";

build({
  plugins: [eta()],
});


TypeScript Types

Declare the module

declare module "*.eta" {
  import type { TemplateFunction } from "eta/dist/types/compile";

  const template: TemplateFunction;
  export default template;
}

Usage

Hello <%= it.hello %>!
import { Eta } from "eta";
import template from "./template.eta";

const eta = new Eta();
const output = eta.render(template, { hello: "World" });

console.log(output);