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-lib-emit-assets

v1.0.3

Published

Vite 插件:提取 lib 构建模式下引用到的资源文件,取代 base64 内联形式

Downloads

52

Readme

vite-plugin-lib-emit-assets

注意:本项目基于 vite-plugin-lib-assets 改造而来。

Vite 插件:用于提取 library mode 构建时引用到的资源文件,而不是以 base64 形式內联它们

安装

npm i vite-plugin-lib-emit-assets -D

yarn add vite-plugin-lib-emit-assets -D

pnpm add vite-plugin-lib-emit-assets -D

使用

// vite.config.ts
import libAssets from 'vite-plugin-lib-emit-assets'

export default defineConfig({
  plugins: [
    libAssets({ /* options */ }),
  ],
})

配置项

export interface Options {
  include?: string | RegExp | (string | RegExp)[]
  exclude?: string | RegExp | (string | RegExp)[]
  name?: string | ((resourcePath: string, resourceQuery: string) => string)
  limit?: number
  publicUrl?: string
}

include

一个或一组 picomatch 表达式,指明哪些文件需要被插件处理。

  • Type: string | RegExp | (string | RegExp)[]
  • Default: 与 Vite assetsInclude 选项的默认值一样,可以在这里找到完整的列表。
  • Example:
    libAssetsPlugin({
      include: /\.a?png(\?.*)?$/
    })

exclude

include 一样,但是用来指明哪些文件需要被插件忽略。

  • Type: string | RegExp | (string | RegExp)[]
  • Default: undefined.
  • Example:
    libAssetsPlugin({
      exclude: /\.svg(\?.*)?$/
    })

name

资源文件的输出名称,与 file-loadername 配置行为一致

  • Type: string | ((resourcePath: string, resourceQuery: string) => string)
  • Default: '[contenthash].[ext]'
  • Example:
    • string
      assetsLibPlugin({
        name: '[name].[contenthash:8].[ext]?[query]'
      })
    • function
      assetsLibPlugin({
        name: (resourcePath, resourceQuery) => {
          // `resourcePath` - `/absolute/path/to/file.js`
          // `resourceQuery` - `foo=bar`
          
          if (process.env.NODE_ENV === 'development') {
            return '[name].[ext]';
          }
          
          return  '[name].[contenthash:8].[ext]?[query]'
        },
      })

完整的占位符列表见 loader-utils#interpolatename

limit

低于 limit 设置体积的文件会以 base64 的格式內联到产物中

  • Type: number,单位 Byte
  • Default: undefined,表示所有文件都不会被内联
  • Example:
    assetsLibPlugin({
      limit: 1024 * 8 // 8KB
    })

publicUrl

资源部署到 CDN 时的路径前缀,这个选项在构建 cjsesm 格式时也会生效

  • Type: string
  • Default: ''
  • Example:
    assetsLibPlugin({
      publicUrl: 'https://cdn.jsdelivr.net/npm/vite-plugin-lib-emit-assets'
    })