Gathering detailed insights and metrics for vite-plugin-html
Gathering detailed insights and metrics for vite-plugin-html
Gathering detailed insights and metrics for vite-plugin-html
Gathering detailed insights and metrics for vite-plugin-html
A vite plugin for processing html. It is developed based on lodash template
npm install vite-plugin-html
55.1
Supply Chain
54.9
Quality
76.7
Maintenance
100
Vulnerability
98.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
605 Stars
82 Commits
96 Forks
6 Watching
2 Branches
16 Contributors
Updated on 29 Nov 2024
Minified
Minified + Gzipped
TypeScript (85.35%)
HTML (7.18%)
JavaScript (3.96%)
Shell (1.85%)
Vue (1.66%)
Cumulative downloads
Total Downloads
Last day
-24.7%
40,814
Compared to previous day
Last week
-8.5%
245,890
Compared to previous week
Last month
-1.7%
1,123,446
Compared to previous month
Last year
50.3%
12,453,574
Compared to previous year
English | ä¸æ–‡
entry
template
node version: >=12.0.0
vite version: >=2.0.0
1yarn add vite-plugin-html -D
或
1npm i vite-plugin-html -D
index.html
, e.g.1<head> 2 <meta charset="UTF-8" /> 3 <link rel="icon" href="/favicon.ico" /> 4 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 5 <title><%- title %></title> 6 <%- injectScript %> 7</head>
vite.config.ts
, this method can introduce the required functions as needed1import { defineConfig, Plugin } from 'vite'
2import vue from '@vitejs/plugin-vue'
3
4import { createHtmlPlugin } from 'vite-plugin-html'
5
6export default defineConfig({
7 plugins: [
8 vue(),
9 createHtmlPlugin({
10 minify: true,
11 /**
12 * After writing entry here, you will not need to add script tags in `index.html`, the original tags need to be deleted
13 * @default src/main.ts
14 */
15 entry: 'src/main.ts',
16 /**
17 * If you want to store `index.html` in the specified folder, you can modify it, otherwise no configuration is required
18 * @default index.html
19 */
20 template: 'public/index.html',
21
22 /**
23 * Data that needs to be injected into the index.html ejs template
24 */
25 inject: {
26 data: {
27 title: 'index',
28 injectScript: `<script src="./inject.js"></script>`,
29 },
30 tags: [
31 {
32 injectTo: 'body-prepend',
33 tag: 'div',
34 attrs: {
35 id: 'tag',
36 },
37 },
38 ],
39 },
40 }),
41 ],
42})
Multi-page application configuration
1import { defineConfig } from 'vite'
2import { createHtmlPlugin } from 'vite-plugin-html'
3
4export default defineConfig({
5 plugins: [
6 createHtmlPlugin({
7 minify: true,
8 pages: [
9 {
10 entry: 'src/main.ts',
11 filename: 'index.html',
12 template: 'public/index.html',
13 injectOptions: {
14 data: {
15 title: 'index',
16 injectScript: `<script src="./inject.js"></script>`,
17 },
18 tags: [
19 {
20 injectTo: 'body-prepend',
21 tag: 'div',
22 attrs: {
23 id: 'tag1',
24 },
25 },
26 ],
27 },
28 },
29 {
30 entry: 'src/other-main.ts',
31 filename: 'other.html',
32 template: 'public/other.html',
33 injectOptions: {
34 data: {
35 title: 'other page',
36 injectScript: `<script src="./inject.js"></script>`,
37 },
38 tags: [
39 {
40 injectTo: 'body-prepend',
41 tag: 'div',
42 attrs: {
43 id: 'tag2',
44 },
45 },
46 ],
47 },
48 },
49 ],
50 }),
51 ],
52})
createHtmlPlugin(options: UserOptions)
Parameter | Types | Default | Description |
---|---|---|---|
entry | string | src/main.ts | entry file path |
template | string | index.html | relative path to the template |
inject | InjectOptions | - | Data injected into HTML |
minify | boolean|MinifyOptions | - | whether to compress html |
pages | PageOption | - | Multi-page configuration |
Parameter | Types | Default | Description |
---|---|---|---|
data | Record<string, any> | - | injected data |
ejsOptions | EJSOptions | - | ejs configuration OptionsEJSOptions |
tags | HtmlTagDescriptor | - | List of tags to inject |
data
can be accessed in html
using the ejs
template syntax
By default, the contents of the .env
file will be injected into index.html, similar to vite's loadEnv
function
Parameter | Types | Default | Description |
---|---|---|---|
filename | string | - | html file name |
template | string | index.html | relative path to the template |
entry | string | src/main.ts | entry file path |
injectOptions | InjectOptions | - | Data injected into HTML |
Default compression configuration
1 collapseWhitespace: true, 2 keepClosingSlash: true, 3 removeComments: true, 4 removeRedundantAttributes: true, 5 removeScriptTypeAttributes: true, 6 removeStyleLinkTypeAttributes: true, 7 useShortDoctype: true, 8 minifyCSS: true,
1pnpm install 2 3# spa 4cd ./packages/playground/basic 5 6pnpm run dev 7 8# map 9cd ./packages/playground/mpa 10 11pnpm run dev 12
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 11/30 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
23 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More