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

@laynezh/vite-plugin-lib-assets

v0.6.1

Published

A Vite Plugin extracts resource files referenced in library mode instead of embedded them as base64.

Downloads

40,985

Readme

English | 中文

@laynezh/vite-plugin-lib-assets

A Vite Plugin extracts resource files referenced in library mode instead of embedded them as base64.

Install

npm i @laynezh/vite-plugin-lib-assets -D

Or

yarn add @laynezh/vite-plugin-lib-assets -D

Or

pnpm add @laynezh/vite-plugin-lib-assets -D

Usage

// vite.config.ts
import libAssetsPlugin from '@laynezh/vite-plugin-lib-assets'

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

Example: playground/

Hints

  • If build.ssr is set to true, you might want to enable build.ssrEmitAssets, so assets are emitted.

Option

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

include

A valid picomatch pattern, or array of patterns indicate which files need to be handled by the plugin.

  • Type: string | RegExp | (string | RegExp)[]
  • Default: Same as Vite's default value for assetsInclude, you can find the complete list here.
  • Example:
    libAssetsPlugin({
      include: /\.a?png(\?.*)?$/
    })

exclude

Same as include, but it is used to indicate the files that should to be omitted.

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

name

Output name of the resource file, its usage aligns with the name option of the file-loader.

  • Type: string
  • Default: '[contenthash].[ext]'
  • Example:
    libAssetsPlugin({
      name: '[name].[contenthash:8].[ext]?[query]'
    })

The complete list can be found at loader-utils#interpolatename

limit

Files larger than the limit will be extracted to the output directory, smaller files will remain embedded in the artifact in base64 format.

  • Type: number,unit Byte
  • Default: undefined,any size of resource files will be extracted
  • Example:
    libAssetsPlugin({
      limit: 1024 * 8 // 8KB
    })

outputPath

Specify the output path where the extracted files will be placed.

  • Type: string | ((url: string, resourcePath: string, resourceQuery: string) => string)
  • Default: Vite's assetsDir configuration.
  • Example:
    • string
      libAssetsPlugin({
        outputPath: 'images'
      })
    • function
      libAssetsPlugin({
        outputPath: (url, resourcePath, resourceQuery) => {
          // `url` - file name processed by the `name` option,eg: `logo.fb2133.png`
          // `resourcePath` - `/original/absolute/path/to/file.js`
          // `resourceQuery` - `foo=bar`
      
          return url.endsWith('.png') ? 'image' : 'assets'
        },
      })

regExp

Specifies a Regular Expression to extract parts of content(capture groups) from the file path and use [N] as placeholders in the name for replacement. Its usage aligns with the regexp option of the file-loader.

  • Type: RegExp
  • Default: undefined
  • Example:
    libAssetsPlugin({
      regExp: /\/([^/]+)\/[^\.]+.png$/,
      name: '[1]-[name].[contenthash:8].[ext]'
    })

publicUrl

Access path prefix for built resource files. Once provided, it will take effect, even while building the cjs and esm formats.

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