You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vite-plugin-parse-html

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-parse-html

just parse html for your inject some script or css, more then inject some data

2.1.0
latest
npmnpm
Version published
Weekly downloads
258
36.51%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-parse-html

npm package npm downloads

🎉 Features

  • Insert variables into the host page through the ejs template engine;

  • Through configuration items, some dynamically inserted javascript and css files are usually used to coordinate with the project externals

  • Indexhtml compression

  • support multi page applications

📦 Installation

  yarn add vite-plugin-parse-html -D

  npm i vite-plugin-parse-html -D

🔨 Usage

1、Use the inject and minify configuration item in vite.config.ts to configure

...
import { inject, minify } from 'vite-plugin-parse-html'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    inject({
      data: {
        title: 'test project',
      },
      sources: [
        'http://xxxx.css',
        'http://xxxx.js',
        { type: 'javascript', url: 'http://yyyy'},
      ],
    }),
    minify({
      isMinify: true,
    }),
    react(),
  ],
})

2、Using plugins in multi page programs

...
import { inject, minify } from 'vite-plugin-parse-html'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    inject([
      {
        path: '/index.html',
        data: {
          title: 'test project',
        },
        sources: [
          'http://xxxx.css',
          'http://xxxx.js',
          { type: 'javascript', url: 'http://yyyy'},
        ],
      },
      {
        path:'/nest/index.html'
        data: {
          title: 'test project',
        },
        sources: [
          'http://xxxx.css',
          'http://xxxx.js',
          { type: 'javascript', url: 'http://yyyy'},
        ],
      }
    ]),
    minify({
      isMinify: true,
    }),
    ...
  ],
})

🔗 Description of inject parameter

  • inject(options: InjectOptions | InjectOptions[])
parametertypedefaultexampledescription
pathstring'/index.html''/nest/index.html'multiple page relative path
dataRecord<string, any>{}{title: 'xxxx'}Variables used on the host page
ejsOptionsOptions
sourcesArray<SourceItemstring>{}[ 'http://xxx.js' ] or [{ url: 'http:xxx.js', type: 'javascript', position: 'head' }]
  • SourceItem
parametertypedefaultexampledescription
type'css' or 'javascript''css'type: 'css'source type
urlstringurl: 'http://xxxxx'source cdn url
position'head' 'body' 'head-prepend' 'body-prepend''head'position: 'head'inject to html position
attrsRecord<string, any>{ async: '' }tags attributes and value

🔗 Description of minify parameter

  • minifyOpt(options: MinifyOptions)
parametertypedefaultexampledescription
isMinifybooleantrueisMinify: trueWhether to compress the host page

Keywords

vite

FAQs

Package last updated on 27 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts