npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-config-html

v1.0.0

Published

This plugin helps us configure html script,meta,link etc.

Downloads

11

Readme

⚡vite-plugin-config-html

npm npm

该插件用于配置入口html,如果想通过环境变量来区分入口html中引入的资源,可以使用此插件。

安装

vite 版本: >=5.0.0

npm install -D vite-plugin-config-html
// 或
yarn add -D vite-plugin-config-html
// 或
pnpm install -D vite-plugin-config-html

选项

title

设置网页标题配置。

favicon

设置收藏夹图标。

metas

设置meta标签。

links

设置link标签。

style

设置style标签。

headScripts

设置头部script标签。

preHeadScripts

在head标签开始位置,设置script标签。

scripts

在body结束标签位置,设置script标签。

用法

// vite.config.ts
import configHtml from 'vite-plugin-config-html'

const options = {
  favicon: './logo.svg',
  headScripts: [
    `var msg = 'head script'
     console.log(msg);`,
    {
      async: true,
      src: 'https://abc.com/b.js',
      type: 'module',
    },
    { content: `console.log('hello')`, charset: 'utf-8' },
  ],
  preHeadScripts: [
    `var msg = 'pre head script'
    console.log(msg);`,
    {
      async: true,
      src: 'https://abc.com/b.js',
      type: 'module',
    },
    { content: `console.log('hello')`, charset: 'utf-8' },
  ],
  scripts: [
    `var msg = 'body script'
     console.log(msg);`,
    {
      async: true,
      src: 'https://abc.com/b.js',
      type: 'module',
    },
  ],
  metas: [
    {
      name: 'keywords',
      content: 'vite html meta keywords',
    },
    {
      name: 'description',
      content: 'vite html meta description',
    },
    {
      bar: 'custom meta',
    },
  ],
  links: [
    {
      rel: 'stylesheet',
      href: './style.css',
    },
    {
      rel: 'modulepreload',
      href: 'https://cn.vitejs.dev/assets/guide_api-plugin.md.6884005a.lean.js',
    },
  ],
  style: `body { color: red; };*{ margin: 0px }`,
}

module.exports = {
  plugins: [configHtml(options)],
}

输出

<!DOCTYPE html>
<html lang="en">
  <head>
    <script>var msg = 'pre head script'
          console.log(msg);</script>
    <script async src="https://abc.com/b.js" type="module"></script>
    <script charset="utf-8">console.log('hello')</script>

    <meta charset="UTF-8">
    <link rel="icon" href="./favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vite App</title>
    <!-- <script src="./iconfont/iconfont.js"></script> -->
    <link rel="shortcut icon" type="image/x-icon" href="./logo.svg">
    <meta name="keywords" content="vite html meta keywords">
    <meta name="description" content="vite html meta description">
    <meta bar="custom meta">
    <link rel="stylesheet" href="./style.css">
    <link rel="modulepreload" href="https://cn.vitejs.dev/assets/guide_api-plugin.md.6884005a.lean.js">
    <style>  body { color: red; };*{ margin: 0px }</style>
    <script>var msg = 'head script'
           console.log(msg);</script>
    <script async src="https://abc.com/b.js" type="module"></script>
    <script charset="utf-8">console.log('hello')</script>
    <script type="module" crossorigin src="./assets/index-C6MUBrDf.js"></script>
    <link rel="stylesheet" crossorigin href="./assets/index-uhSYYSbM.css">
    <script src="assets/iconfont1.js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script>var msg = 'body script'
           console.log(msg);</script>
    <script async src="https://abc.com/b.js" type="module"></script>
  </body>
</html>