New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-inject-html

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-inject-html

- [`favicon`](#favicon) - favicon url - [`title`](#title) - title - [`metas`](#metas) - `<meta>` tags - [`links`](#links) - `<link>` tags - [`externalStyleSheets`](#externalStyleSheets) - external style sheet urls - [`scripts`](#scripts) - `<script>`

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
decreased by-18.18%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-inject-html npm package

Options

favicon

// vite.config.ts
import { defineConfig } from 'vite'
import injectHTMLPlugin from 'vite-plugin-inject-html'

export default defineConfig({
  plugins: [
    injectHTMLPlugin({
      favicon: 'https://example.com/favicon.ico'
    })
  ]
})
<!-- index.html -->
<head>
  <link rel="icon" href="https://example.com/favicon.ico" />
</head>

title

  • It will replace the existing <title> tag
// vite.config.ts
import { defineConfig } from 'vite'
import injectHTMLPlugin from 'vite-plugin-inject-html'

export default defineConfig({
  plugins: [
    injectHTMLPlugin({
      title: 'My App'
    })
  ]
})
<!-- index.html -->
<head>
  <title>My App</title>
</head>

metas

// vite.config.ts
import { defineConfig } from 'vite'
import injectHTMLPlugin from 'vite-plugin-inject-html'

export default defineConfig({
  plugins: [
    injectHTMLPlugin({
      metas: [
        {
          name: 'description',
          content: 'My App'
        }
      ]
    })
  ]
})
<!-- index.html -->
<head>
  <meta name="description" content="My App" />
</head>
// vite.config.ts
import { defineConfig } from 'vite'
import injectHTMLPlugin from 'vite-plugin-inject-html'

export default defineConfig({
  plugins: [
    injectHTMLPlugin({
      links: [
        {
          rel: 'stylesheet',
          href: 'https://example.com/style.css'
        }
      ]
    })
  ]
})
<!-- index.html -->
<head>
  <link rel="stylesheet" href="https://example.com/style.css" />
</head

externalStyleSheets

// vite.config.ts
import { defineConfig } from 'vite'
import injectHTMLPlugin from 'vite-plugin-inject-html'

export default defineConfig({
  plugins: [
    injectHTMLPlugin({
      externalStyleSheets: [
        'https://example.com/style.css',
        'https://example.com/style2.css'
      ]
    })
  ]
})
<!-- index.html -->
<head>
  <link rel="stylesheet" type="text/css" href="https://example.com/style.css" />
  <link rel="stylesheet" type="text/css" href="https://example.com/style2.css" />
</head

scripts

  • injectTo can be head-prepend, head, body-prepend or body, default to body
// vite.config.ts
import { defineConfig } from 'vite'
import injectHTMLPlugin from 'vite-plugin-inject-html'

export default defineConfig({
  plugins: [
    injectHTMLPlugin({
      scripts: [
        `console.log('String Content 1')`,
        {
          children: `console.log('String Content 2')`,
          injectTo: 'head-prepend'
        },
        {
          src: 'https://example.com/script.js',
          attributes: { async: true },
          injectTo: 'body-prepend'
        }
      ]
    })
  ]
})
<!-- index.html -->
<head>
  <script>
    console.log('String Content 2')
  </script>
</head>
<body>
  <script src="https://example.com/script.js"></script>
  <script>
    console.log('String Content 1')
  </script>
</body>

noscripts

  • injectTo can be head-prepend, head, body-prepend or body, default to body
// vite.config.ts
import { defineConfig } from 'vite'
import injectHTMLPlugin from 'vite-plugin-inject-html'

export default defineConfig({
  plugins: [
    injectHTMLPlugin({
      noscripts: [
        `console.log('String Content 1')`,
        {
          children: `console.log('String Content 2')`,
          injectTo: 'body-prepend'
        }
      ]
    })
  ]
})
<!-- index.html -->
<body>
  <noscript>
    console.log('String Content 2')
  </noscript>
  <noscript>
    console.log('String Content 1')
  </noscript>
</body>

otherTags

  • injectTo can be head-prepend, head, body-prepend or body, default to head-prepend
// vite.config.ts
import { defineConfig } from 'vite'
import injectHTMLPlugin from 'vite-plugin-inject-html'

export default defineConfig({
  plugins: [
    injectHTMLPlugin({
      otherTags: [
        {
          tagName: 'h1',
          attrs: { id: 'title' },
          children: 'Hello World',
          injectTo: 'body'
        }
      ]
    })
  ]
})
<!-- index.html -->
<body>
  <h1 id="title">Hello World</h1>
</body>

FAQs

Package last updated on 11 Feb 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc