1.3.0 • Published 1 year ago

vite-plugin-esi v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

vite-plugin-esi

Vite plugin to resolve ESI with nodesi.

Getting Started

Installation

npm i -D vite-plugin-esi
yarn add -D vite-plugin-esi
pnpm add -D vite-plugin-esi

Basic Usage

Use the required esi option to define ESI tags to be resolved. The keys of the object are the names of the html comments that will be replaced with the resolved ESI tags.

This plugin uses html comments to determine where the ESI tags (or resolved ESI tags) should be placed.

Comments must be in the following format:

<!--vite-plugin-esi name="somename" -->
// vite.config.ts
import { defineConfig } from 'vite'
import viteEsi from 'vite-plugin-esi'

export default defineConfig({
  plugins: [
    viteEsi({
        esi: {
            headFragments: [
                { src: "http://localhost:3000/esi/fragment1" },
                { src: "http://localhost:3000/esi/fragment2" }
            ]
        }
    })
  ]
})
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ESI Demo</title>
    <!--vite-plugin-esi name="headFragments" -->
</head>
<body>
    ....
</body>
</html>

Options

nametypeoptionaldefaultdescription
esiOptionsNodeEsiOptions \| undefinedtruen/aPassed to nodesi.
esi{ [name: string]: Tag[]; }falsen/a
resolveESIboolean \| undefinedtruetrueIf ESI tags should be resolved to html, or to keep them as-is in the final html.

Examples

Keep ESI tags

If your production server is responsible for resolving ESI tags, you can set the resolveESI option to false to keep the tags as-is in the final html.

// vite.config.ts
import { defineConfig } from 'vite'
import viteEsi from 'vite-plugin-esi'

export default defineConfig({
  plugins: [
    viteEsi({
        resolveESI: false,
        esi: {
            headFragments: [
                { src: "http://localhost:3000/esi/fragment1" },
                { src: "http://localhost:3000/esi/fragment2" }
            ]
        }
    })
  ]
})
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ESI Demo</title>
    <!--vite-plugin-esi name="headFragments" -->
</head>
<body>
    ....
</body>
</html>
<!-- index.html (after build) -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ESI Demo</title>
    <esi:include src="http://localhost:3000/esi/fragment1" onerror="abort"></esi:include>
    <esi:include src="http://localhost:3000/esi/fragment2" onerror="abort"></esi:include>
</head>
<body>
    ....
</body>
</html>
1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.2.4

1 year ago

1.0.6

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

0.0.1

1 year ago