Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/donnikitos/vite-plugin-html-inject

Split your ViteJS index.html into smaller pieces
https://github.com/donnikitos/vite-plugin-html-inject

front-end front-end-development frontend frontend-web static-site static-site-generator vite vite-plugin vite-plugin-html-inject vitejs

Last synced: about 2 months ago
JSON representation

Split your ViteJS index.html into smaller pieces

Awesome Lists containing this project

README

        

# vite-plugin-html-inject

[![npm](https://img.shields.io/npm/dt/vite-plugin-html-inject?style=for-the-badge)](https://www.npmjs.com/package/vite-plugin-html-inject) ![GitHub Repo stars](https://img.shields.io/github/stars/donnikitos/vite-plugin-html-inject?label=GitHub%20Stars&style=for-the-badge) [![GitHub](https://img.shields.io/github/license/donnikitos/vite-plugin-html-inject?color=blue&style=for-the-badge)](https://github.com/donnikitos/vite-plugin-html-inject/blob/master/LICENSE)
![GitHub last commit](https://img.shields.io/github/last-commit/donnikitos/vite-plugin-html-inject?style=for-the-badge) [![Issues](https://img.shields.io/github/issues/donnikitos/vite-plugin-html-inject?style=for-the-badge)](https://github.com/donnikitos/vite-plugin-html-inject/issues)

Split your `index.html` into smaller, reusable static HTML pieces.

```js
// vite.config.js
import { defineConfig } from 'vite';
import injectHTML from 'vite-plugin-html-inject';

export default defineConfig({
plugins: [injectHTML()],
});
```

## Load those sweet separate HTML files

```html
















```

## Pass down static arguments to injected HTML parts

The plugin also allows you to supply your HTML parts with some basic arguments, so you can reuse the same piece of code in multiple places.

For example you can reuse a similarly styled link somewhere in your `index.html`:

```html

...






...
```

And that `src/some-static-link.htm`:

```html

{=$label}
```

This will result in a dev and runtime generated index.html looking like

```html

...


...
```

## Customization

You are able to customize the loader tag name and the source attribute name.\
For example a configuration like:

```js
injectHTML({
tagName: 'loader', // Default is `load`
sourceAttr: 'file', // Default is `src`
});
```

will replace:

```html

```

## Debugging

By default the debugging option is turned off. However, if you encounter issues loading files, you can turn on path logging.

```js
injectHTML({
debug: {
logPath: true,
},
});
```

## Support

Love open source? Enjoying my project?\
Your support can keep the momentum going! Consider a donation to fuel the creation of more innovative open source software.

| via Ko-Fi | Buy me a coffee | via PayPal |
| --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y2ALMG) | Buy Me A Coffee | PayPal |