@linglongos/vite-plugin-html 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -0
- package/README.zh_CN.md +148 -0
- package/package.json +8 -1
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @linglongos/vite-plugin-html
|
|
2
|
+
|
|
3
|
+
Forked from [vite-plugin-html](https://www.npmjs.com/package/vite-plugin-html) with **Vite 6/7/8 support** and modernized dependencies.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- HTML compression capability
|
|
8
|
+
- EJS template capability
|
|
9
|
+
- Multi-page application support
|
|
10
|
+
- Support custom `entry`
|
|
11
|
+
- Support custom `template`
|
|
12
|
+
- **Vite 6/7/8 support** - Active maintenance and compatibility updates
|
|
13
|
+
- **Rolldown compatible** - Built for Vite 8's new architecture
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# using npm
|
|
19
|
+
npm install @linglongos/vite-plugin-html -D
|
|
20
|
+
|
|
21
|
+
# using yarn
|
|
22
|
+
yarn add @linglongos/vite-plugin-html -D
|
|
23
|
+
|
|
24
|
+
# using pnpm
|
|
25
|
+
pnpm add @linglongos/vite-plugin-html -D
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- **Node.js**: >=18.0.0
|
|
31
|
+
- **Vite**: >=2.0.0
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
### 1. Add EJS tags to `index.html`
|
|
36
|
+
|
|
37
|
+
```html
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="UTF-8" />
|
|
40
|
+
<link rel="icon" href="/favicon.ico" />
|
|
41
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
42
|
+
<title><%- title %></title>
|
|
43
|
+
<%- injectScript %>
|
|
44
|
+
</head>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. Configure in `vite.config.ts`
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { defineConfig } from 'vite'
|
|
51
|
+
import vue from '@vitejs/plugin-vue'
|
|
52
|
+
import { createHtmlPlugin } from '@linglongos/vite-plugin-html'
|
|
53
|
+
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
plugins: [
|
|
56
|
+
vue(),
|
|
57
|
+
createHtmlPlugin({
|
|
58
|
+
minify: true,
|
|
59
|
+
entry: 'src/main.ts',
|
|
60
|
+
template: 'public/index.html',
|
|
61
|
+
inject: {
|
|
62
|
+
data: {
|
|
63
|
+
title: 'index',
|
|
64
|
+
injectScript: `<script src="./inject.js"></script>`,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
],
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Multi-Page Application
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { defineConfig } from 'vite'
|
|
76
|
+
import { createHtmlPlugin } from '@linglongos/vite-plugin-html'
|
|
77
|
+
|
|
78
|
+
export default defineConfig({
|
|
79
|
+
plugins: [
|
|
80
|
+
createHtmlPlugin({
|
|
81
|
+
minify: true,
|
|
82
|
+
pages: [
|
|
83
|
+
{
|
|
84
|
+
entry: 'src/main.ts',
|
|
85
|
+
filename: 'index.html',
|
|
86
|
+
template: 'public/index.html',
|
|
87
|
+
injectOptions: {
|
|
88
|
+
data: {
|
|
89
|
+
title: 'index',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
entry: 'src/other-main.ts',
|
|
95
|
+
filename: 'other.html',
|
|
96
|
+
template: 'public/other.html',
|
|
97
|
+
injectOptions: {
|
|
98
|
+
data: {
|
|
99
|
+
title: 'other page',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## API Reference
|
|
110
|
+
|
|
111
|
+
### UserOptions
|
|
112
|
+
|
|
113
|
+
| Parameter | Type | Default | Description |
|
|
114
|
+
| ----------- | ------------------------ | ------------- | ------------------------------ |
|
|
115
|
+
| entry | `string` | `src/main.ts` | Entry file path |
|
|
116
|
+
| template | `string` | `index.html` | Relative path to the template |
|
|
117
|
+
| inject | `InjectOptions` | - | Data injected into HTML |
|
|
118
|
+
| minify | `boolean \| MinifyOptions` | - | Whether to compress html |
|
|
119
|
+
| pages | `PageOption` | - | Multi-page configuration |
|
|
120
|
+
|
|
121
|
+
### InjectOptions
|
|
122
|
+
|
|
123
|
+
| Parameter | Type | Default | Description |
|
|
124
|
+
| ---------- | ---------------------- | ------- | ---------------------------------------------- |
|
|
125
|
+
| data | `Record<string, any>` | - | Injected data (accessible via EJS syntax) |
|
|
126
|
+
| ejsOptions | `EJSOptions` | - | EJS configuration |
|
|
127
|
+
| tags | `HtmlTagDescriptor` | - | List of tags to inject |
|
|
128
|
+
|
|
129
|
+
### PageOption
|
|
130
|
+
|
|
131
|
+
| Parameter | Type | Default | Description |
|
|
132
|
+
| ------------- | --------------- | ------------- | ----------------------------- |
|
|
133
|
+
| filename | `string` | - | HTML file name |
|
|
134
|
+
| template | `string` | `index.html` | Relative path to the template |
|
|
135
|
+
| entry | `string` | `src/main.ts` | Entry file path |
|
|
136
|
+
| injectOptions | `InjectOptions`| - | Data injected into HTML |
|
|
137
|
+
|
|
138
|
+
## Environment Variables
|
|
139
|
+
|
|
140
|
+
By default, the contents of the `.env` file will be injected into index.html, similar to Vite's `loadEnv` function.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
Forked from [vite-plugin-html](https://www.npmjs.com/package/vite-plugin-html)
|
package/README.zh_CN.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @linglongos/vite-plugin-html
|
|
2
|
+
|
|
3
|
+
基于 [vite-plugin-html](https://www.npmjs.com/package/vite-plugin-html) fork,**支持 Vite 6/7/8**,持续更新维护。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- HTML 压缩能力
|
|
8
|
+
- EJS 模板能力
|
|
9
|
+
- 多页应用支持
|
|
10
|
+
- 支持自定义 `entry`
|
|
11
|
+
- 支持自定义 `template`
|
|
12
|
+
- **Vite 6/7/8 支持** - 持续更新维护
|
|
13
|
+
- **Rolldown 兼容** - 基于 Vite 8 新架构构建
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 使用 npm
|
|
19
|
+
npm install @linglongos/vite-plugin-html -D
|
|
20
|
+
|
|
21
|
+
# 使用 yarn
|
|
22
|
+
yarn add @linglongos/vite-plugin-html -D
|
|
23
|
+
|
|
24
|
+
# 使用 pnpm
|
|
25
|
+
pnpm add @linglongos/vite-plugin-html -D
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 环境要求
|
|
29
|
+
|
|
30
|
+
- **Node.js**: >=18.0.0
|
|
31
|
+
- **Vite**: >=2.0.0
|
|
32
|
+
|
|
33
|
+
## 快速开始
|
|
34
|
+
|
|
35
|
+
### 1. 在 `index.html` 中添加 EJS 标签
|
|
36
|
+
|
|
37
|
+
```html
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="UTF-8" />
|
|
40
|
+
<link rel="icon" href="/favicon.ico" />
|
|
41
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
42
|
+
<title><%- title %></title>
|
|
43
|
+
<%- injectScript %>
|
|
44
|
+
</head>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. 在 `vite.config.ts` 中配置
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { defineConfig } from 'vite'
|
|
51
|
+
import vue from '@vitejs/plugin-vue'
|
|
52
|
+
import { createHtmlPlugin } from '@linglongos/vite-plugin-html'
|
|
53
|
+
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
plugins: [
|
|
56
|
+
vue(),
|
|
57
|
+
createHtmlPlugin({
|
|
58
|
+
minify: true,
|
|
59
|
+
entry: 'src/main.ts',
|
|
60
|
+
template: 'public/index.html',
|
|
61
|
+
inject: {
|
|
62
|
+
data: {
|
|
63
|
+
title: 'index',
|
|
64
|
+
injectScript: `<script src="./inject.js"></script>`,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
],
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 多页应用配置
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { defineConfig } from 'vite'
|
|
76
|
+
import { createHtmlPlugin } from '@linglongos/vite-plugin-html'
|
|
77
|
+
|
|
78
|
+
export default defineConfig({
|
|
79
|
+
plugins: [
|
|
80
|
+
createHtmlPlugin({
|
|
81
|
+
minify: true,
|
|
82
|
+
pages: [
|
|
83
|
+
{
|
|
84
|
+
entry: 'src/main.ts',
|
|
85
|
+
filename: 'index.html',
|
|
86
|
+
template: 'public/index.html',
|
|
87
|
+
injectOptions: {
|
|
88
|
+
data: {
|
|
89
|
+
title: 'index',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
entry: 'src/other-main.ts',
|
|
95
|
+
filename: 'other.html',
|
|
96
|
+
template: 'public/other.html',
|
|
97
|
+
injectOptions: {
|
|
98
|
+
data: {
|
|
99
|
+
title: 'other page',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## API 参考
|
|
110
|
+
|
|
111
|
+
### UserOptions
|
|
112
|
+
|
|
113
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
114
|
+
| -------- | ------------------------ | ------------- | ------------------ |
|
|
115
|
+
| entry | `string` | `src/main.ts` | 入口文件路径 |
|
|
116
|
+
| template | `string` | `index.html` | 模板相对路径 |
|
|
117
|
+
| inject | `InjectOptions` | - | 注入 HTML 的数据 |
|
|
118
|
+
| minify | `boolean \| MinifyOptions` | - | 是否压缩 html |
|
|
119
|
+
| pages | `PageOption` | - | 多页配置 |
|
|
120
|
+
|
|
121
|
+
### InjectOptions
|
|
122
|
+
|
|
123
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
124
|
+
| ---------- | --------------------- | ------ | -------------------------- |
|
|
125
|
+
| data | `Record<string, any>` | - | 注入的数据 (可用 EJS 语法访问) |
|
|
126
|
+
| ejsOptions | `EJSOptions` | - | EJS 配置项 |
|
|
127
|
+
| tags | `HtmlTagDescriptor` | - | 需要注入的标签列表 |
|
|
128
|
+
|
|
129
|
+
### PageOption
|
|
130
|
+
|
|
131
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
132
|
+
| ------------- | --------------- | ------------- | ---------------- |
|
|
133
|
+
| filename | `string` | - | HTML 文件名 |
|
|
134
|
+
| template | `string` | `index.html` | 模板相对路径 |
|
|
135
|
+
| entry | `string` | `src/main.ts` | 入口文件路径 |
|
|
136
|
+
| injectOptions | `InjectOptions`| - | 注入 HTML 的数据 |
|
|
137
|
+
|
|
138
|
+
## 环境变量注入
|
|
139
|
+
|
|
140
|
+
默认会向 index.html 注入 `.env` 文件的内容,类似 Vite 的 `loadEnv` 函数。
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
基于 [vite-plugin-html](https://www.npmjs.com/package/vite-plugin-html) fork
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linglongos/vite-plugin-html",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Fork of vite-plugin-html with Vite 8 support, EJS template and HTML minification for index.html",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,6 +32,13 @@
|
|
|
32
32
|
],
|
|
33
33
|
"author": "Vben",
|
|
34
34
|
"license": "MIT",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18.0.0"
|
|
37
|
+
},
|
|
38
|
+
"funding": {
|
|
39
|
+
"type": "individual",
|
|
40
|
+
"url": "https://www.npmjs.com"
|
|
41
|
+
},
|
|
35
42
|
"repository": {
|
|
36
43
|
"type": "git",
|
|
37
44
|
"url": "https://github.com/vbenjs/vite-plugin-html",
|