Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vite-plugin-esi

marcusthelin6.9kMIT1.3.0TypeScript support: included

Vite plugin to resolve ESI with nodesi.

vite, vite plugin, esi, nodesi

readme

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

name type optional default description
esiOptions NodeEsiOptions | undefined true n/a Passed to nodesi.
esi { [name: string]: Tag[]; } false n/a
resolveESI boolean | undefined true true If 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>

changelog

Changelog

1.3.1 (2024-04-29)

Bug Fixes

1.3.0 (2024-04-29)

Features

1.2.4 (2024-04-26)

Bug Fixes

1.2.3 (2024-04-26)

Bug Fixes

1.2.2 (2024-04-26)

Bug Fixes

1.2.1 (2024-04-26)

Bug Fixes

1.2.0 (2024-04-26)

Features

1.1.0 (2024-04-26)

Features

1.0.9 (2024-04-26)

Bug Fixes

  • Refactor and easier to read code (a5f00f8)

1.0.8 (2024-04-26)

Bug Fixes

  • Exclude tests from dist (97c073e)

1.0.7 (2024-04-26)

Bug Fixes

1.0.6 (2024-04-26)

Bug Fixes

1.0.6 (2024-04-26)

Bug Fixes

1.0.5 (2024-01-27)

Documentation

1.0.4 (2024-01-27)

Miscellaneous Chores

  • Set urls in package json (9c04327)

1.0.3 (2024-01-26)

Miscellaneous Chores

1.0.2 (2024-01-26)

Bug Fixes

  • ci: Specify pnpm version 8 (08df896)

1.0.1 (2024-01-26)

Bug Fixes

  • ci: Setup pnpm and do install (1e794e9)

1.0.0 (2024-01-26)

Bug Fixes