From 0dcbc890317c50eee85f713b5157544c5b70d0b4 Mon Sep 17 00:00:00 2001 From: deirn Date: Sun, 7 Apr 2024 22:15:10 +0700 Subject: [PATCH] add readme, fix regex --- README.md | 67 ++++++++++++++++++++++++++++++---------------------- src/index.ts | 2 +- src/types.ts | 1 - 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 479fc19..a764129 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,13 @@ -# unplugin-starter +# unplugin-eta3 -[![NPM version](https://img.shields.io/npm/v/unplugin-starter?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-starter) +[![NPM version](https://img.shields.io/npm/v/unplugin-eta3?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-eta3) -Starter template for [unplugin](https://github.com/unjs/unplugin). - -## Template Usage - -To use this template, clone it down using: - -```bash -npx degit unplugin/unplugin-starter my-unplugin -``` - -And do a global replacement of `unplugin-starter` with your plugin name. - -Then you can start developing your unplugin 🔥 - -To test your plugin, run: `pnpm run dev` -To release a new version, run: `pnpm run release` +Plugin to precompile Eta functions, making it possible to be used in serverless context like Cloudflare Workers. ## Install ```bash -npm i unplugin-starter +npm i --save-dev unplugin-eta3 ```
@@ -30,11 +15,11 @@ npm i unplugin-starter ```ts // vite.config.ts -import Starter from "unplugin-starter/vite"; +import eta from "unplugin-eta3/vite"; export default defineConfig({ plugins: [ - Starter({ /* options */ }), + eta({ /* options */ }), ], }); ``` @@ -48,11 +33,11 @@ Example: [`playground/`](./playground/) ```ts // rollup.config.js -import Starter from "unplugin-starter/rollup"; +import eta from "unplugin-eta3/rollup"; export default { plugins: [ - Starter({ /* options */ }), + eta({ /* options */ }), ], }; ``` @@ -68,7 +53,7 @@ export default { module.exports = { /* ... */ plugins: [ - require("unplugin-starter/webpack")({ /* options */ }) + require("unplugin-eta3/webpack")({ /* options */ }) ] }; ``` @@ -82,7 +67,7 @@ module.exports = { // nuxt.config.js export default defineNuxtConfig({ modules: [ - ["unplugin-starter/nuxt", { /* options */ }], + ["unplugin-eta3/nuxt", { /* options */ }], ], }); ``` @@ -99,7 +84,7 @@ export default defineNuxtConfig({ module.exports = { configureWebpack: { plugins: [ - require("unplugin-starter/webpack")({ /* options */ }), + require("unplugin-eta3/webpack")({ /* options */ }), ], }, }; @@ -113,11 +98,37 @@ module.exports = { ```ts // esbuild.config.js import { build } from "esbuild"; -import Starter from "unplugin-starter/esbuild"; +import eta from "unplugin-eta3/esbuild"; build({ - plugins: [Starter()], + plugins: [eta()], }); ```
+ +## TypeScript Types +Declare the module +```typescript +declare module "*.eta" { + import type { TemplateFunction } from "eta/dist/types/compile"; + + const template: TemplateFunction; + export default template; +} +``` + +## Usage +```eta +Hello <%= it.hello %>! +``` + +```typescript +import { Eta } from "eta"; +import template from "./template.eta"; + +const eta = new Eta(); +const output = eta.render(template, { hello: "World" }); + +console.log(output); +``` \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index ef08756..60db4a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { createUnplugin } from "unplugin"; import type { Options } from "./types"; export const unpluginFactory: UnpluginFactory = function (options) { - const include = options?.include ?? [/.eta$/]; + const include = options?.include ?? [/\.eta$/]; const eta = new Eta(options?.eta); return { diff --git a/src/types.ts b/src/types.ts index 98213fa..a16f13f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,4 +12,3 @@ export interface Options { */ eta?: Partial } -