Skip to content

Commit

Permalink
add readme, fix regex
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Apr 7, 2024
1 parent c6d0660 commit 0dcbc89
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
67 changes: 39 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
# 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
```

<details>
<summary>Vite</summary><br>

```ts
// vite.config.ts
import Starter from "unplugin-starter/vite";
import eta from "unplugin-eta3/vite";

export default defineConfig({
plugins: [
Starter({ /* options */ }),
eta({ /* options */ }),
],
});
```
Expand All @@ -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 */ }),
],
};
```
Expand All @@ -68,7 +53,7 @@ export default {
module.exports = {
/* ... */
plugins: [
require("unplugin-starter/webpack")({ /* options */ })
require("unplugin-eta3/webpack")({ /* options */ })
]
};
```
Expand All @@ -82,7 +67,7 @@ module.exports = {
// nuxt.config.js
export default defineNuxtConfig({
modules: [
["unplugin-starter/nuxt", { /* options */ }],
["unplugin-eta3/nuxt", { /* options */ }],
],
});
```
Expand All @@ -99,7 +84,7 @@ export default defineNuxtConfig({
module.exports = {
configureWebpack: {
plugins: [
require("unplugin-starter/webpack")({ /* options */ }),
require("unplugin-eta3/webpack")({ /* options */ }),
],
},
};
Expand All @@ -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()],
});
```

<br></details>

## 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);
```
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createUnplugin } from "unplugin";
import type { Options } from "./types";

export const unpluginFactory: UnpluginFactory<Options | undefined> = function (options) {
const include = options?.include ?? [/.eta$/];
const include = options?.include ?? [/\.eta$/];
const eta = new Eta(options?.eta);

return {
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ export interface Options {
*/
eta?: Partial<EtaConfig>
}

0 comments on commit 0dcbc89

Please sign in to comment.