Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jstors/farm-plugin-html-template

This plugin is used to dynamically replace variables injected into HTML.
https://github.com/jstors/farm-plugin-html-template

Last synced: 2 months ago
JSON representation

This plugin is used to dynamically replace variables injected into HTML.

Awesome Lists containing this project

README

        

# farm-plugin-html-template
![NPM Version](https://img.shields.io/npm/v/%40jstors%2Ffarm-plugin-html-template)

This plugin is used to dynamically replace variables like `${var}$` injected into HTML.

## Installation

```bash
npm install -D @jstors/farm-plugin-html-template
# or
yarn add -D @jstors/farm-plugin-html-template
#or
pnpm install -D @jstors/farm-plugin-html-template
```
## Usage

### Configuration

Note that if you want to replace the variables correctly, you must define them correctly inside the configured `data`.

If there is no match in the `data` field for the variable you defined, then it won't be replaced.

```javascript
import farmPluginHtmlTemplate from '@jstors/arm-plugin-html-template';
import { defineConfig } from "@farmfe/core";

export default defineConfig({
// plugin configuration
plugins: [
["@jstors/farm-plugin-html-template",
{
template: path.resolve(__dirname, 'index.html'),
data: {
title: 'Hello World',
description: 'This is a description',
keywords: 'html, template, farm'
}
}]
],
});
```
### HTML Template

- `pre-conversion`
```html

${title}$

```
- `converted`

```html

Hello World

```

## Options

- `template`: The path to the HTML file that will be used as a template.
- `data`: An object containing the variables that will be injected into the HTML file.