2.1.0 β€’ Published 1 year ago

vite-plugin-parse-html v2.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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
2.1.0

1 year ago

2.0.0

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago