Skip to content
PluginStats

vite-plugin-lib-inject-css weekly downloads statistics

By emosheeep (2 listings) · npm · Vite plugins

Inject css at the top of chunk file in lib mode using `import` statement, support multiple entries.

View on npm Fresh · Dec 6, 2026

vite-plugin-lib-inject-css has 454,101 recorded weekly downloads on npm, a decrease of 13.4% over the past 30 days, ranking #409 of 3,247 tracked listings.

Weekly downloads
454,101
Official API · Dec 5, 2026
7-day growth
+15.6%
+61.3K weekly downloads
30-day growth
-13.4%
-70.5K weekly downloads
90-day growth
+37.9%
+124.9K weekly downloads
Rank
#409
▲ 9 in 7 days

About vite-plugin-lib-inject-css

vite-plugin-lib-inject-css

npm version weekly downloads license stars

English | 简体中文

Inject css at the top of each chunk file in library mode using import statement, support multi-entries build, especially to help building component libraries.

// bundled js file, with import css at top (if any)
import './style.css';
// rest of the file
// ...

Can css be styleInjected in library mode? vite#1579.

Features

Note that this plugin only works with library-mode.

  • 💡 Multiple entires support.
  • ⚡️ Sourcemap support.
  • 💻 SSR build support.
  • 🛠 Out-of-box, tiny and pretty.

Quick Experience

View the cloud ide on stackblitz.com, and setup with the following scripts:

pnpm install
cd example
pnpm build

Usage

pnpm i vite-plugin-lib-inject-css -D # npm/yarn
// vite.config.ts
import { libInjectCss } from 'vite-plugin-lib-inject-css';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    libInjectCss(),
  ],
  build: {
    lib: {
      formats: ['es'],
      entry: {
        index: 'src/index.ts',
        button: 'src/components/button/index.ts',
        select: 'src/components/select/index.ts',
      },
    }
    rollupOptions: {
      output: {
        // Put chunk files at <output>/chunks
        chunkFileNames: 'chunks/[name].[hash].js',
        // Put chunk styles at <output>/assets
        assetFileNames: 'assets/[name][extname]',
        entryFileNames: '[name].js',
      },
    },
  }
})

Motivation

Vite shines in Web project development, but it can also be used for library projects.

But when it comes to component library development, multiple entries are often involved. Although Vite 3.2+ later supports multiple entry points, it doesn't provide relevant options for us to associate css with component, which leads to the problem that we can't distinguish between the entry point and css files even though the bundle is successful.

Based on this, we need to write a plugin to try to find the relationship between the two, and inject styles correctly.

How does It Work

As a library(mostly component library), we want to import styles automatically when referencing the component.

/** component-lib/dist/button.js */
import './assets/button.css'; // This is what this plugin do;
...
export default Button;

/** component-lib/dist/index.js */
import Button from './button.js';
import xxx from './xxx.js';
export { Button, xxx };
...

/** In our project's main file */
// Once we import Button, styles'll be imported together.
import { Button } from 'component-lib';

The simplest way is to add a line import './style.css'; to the top of the generated file, multiple lines are multiple lines. As a library provider, we should provide flexibility as much as possible, and delegate the task of how to handle these css files to the user's build tool.

But most of the Vite plugins on the market that claim to automatically inject CSS are designed in a way use document.createElement ('style'), which is not graceful, and it assumes that the current is in the Browser's DOM environment, which makes the library SSR-incompatible.

Here's the reply(vite#issuecomment) of the author of Vite, Evan You.

So the main problem becomes to how do we know which style files are involved in one chunk file?

In fact, vite adds a property named viteMetadata on each chunk file in plugin lifecycle, you can check css.ts for further information.

We can get which resources(include CSS files) are associated with current chunk file by using this property. Based on this, the plugin injects styles by using renderChunk hook, which is the simplest and most effective way.

Prefer to check plugin source code to get more information and welcome to make contribution, which is simple enough(100+ lines).

Recipes of Creating Component Library

How do we create a component library with vite, which can auto import styles and has out-of-box tree-shaking functionality?

Most of component libraries provide two ways. One is totally import:

import Vue from 'vue';
import XxxUI from 'component-lib';
Vue.use(XxxUI);

The other is import on demand, in common uses with a third-part plugin like babel-plugin-import:

import { Button } from 'component-lib';
// ↓ ↓ ↓ transformed ↓ ↓ ↓
import Button from 'component-lib/dist/button/index.js'
import 'component-lib/dist/button/style.css'

But the best way is that when we use named imports, the style imports and tree-shaking can be applied automatically.

How Should We do

Fortunately, ES Module naturally has static analysis capabilities, and mainstream tools basically implement ESM-based Tree-shaking functions, such as webpack/rollup/vite.

Then we only need the following three steps:

  1. Adjust the output format to ES Module → Out-of-the-box Tree-shaking functionality.
  2. Use this plugin for style injection → auto import styles
  3. The last and most important, add all of the entry files you’ve exported in main.js to your rollup.input configurations.…

Description from the npm listing.

  • vite
  • plugin
  • lib
  • build
  • vite-lib
  • vite-plugin
  • vite-build
  • css
  • style
  • styles
  • inject
  • inline

README badge

Show your rank in a README or on your website. The badge updates automatically.

Charts

Images: 30d · 1y · all time · 1600×900 dark

Adoption over time

vite-plugin-lib-inject-css weekly downloads on npm, last 90 days: 454,101 weekly downloads as of Dec 5, 2026, +37.9% over 90 days.vite-plugin-lib-inject-cssWeekly downloads on npm · Last 90 days454,101downloads / week+37.9% over 90 days0100K200K300K400K500K600KSep 6Sep 21Oct 6Oct 21Nov 5Nov 20Dec 5downloads / weekobservedarchived (Internet Archive)no observationsSep 7, 2026 – Dec 5, 2026 · 90 observations · Updated Dec …pluginstats.com
vite-plugin-lib-inject-css weekly downloads on npm, last 90 days: 454,101 weekly downloads as of Dec 5, 2026, +37.9% over 90 days.

7/30/90-day growth

vite-plugin-lib-inject-css weekly downloads growth on npm: +15.6% over 7 days, -13.4% over 30 days, +37.9% over 90 days.vite-plugin-lib-inject-cssWeekly downloads growth on npm454,101downloads / week now7-day growth+61,300 weekly downloads+15.6%30-day growth-70,501 weekly downloads-13.4%90-day growth+124,856 weekly downloads+37.9%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
vite-plugin-lib-inject-css weekly downloads growth on npm: +15.6% over 7 days, -13.4% over 30 days, +37.9% over 90 days.

Ranking history

vite-plugin-lib-inject-css npm ranking history: currently #409 (by weekly downloads).vite-plugin-lib-inject-cssnpm ranking · by weekly downloads · Last 90 days#409current rank#350#360#370#380#390#400#410#420Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 18, 2026 – Dec 6, 2026 · 44 observations · Updated Dec 5, 2026pluginstats.com
vite-plugin-lib-inject-css npm ranking history: currently #409 (by weekly downloads).

Listing placement

All npm3,247 listings · 163 pages · 1,083 shown · page 21, #9 (overall #409)
All npm: every listing in weekly downloads order

Listing placement

Vite plugins300 listings · 15 pages · page 3, #16 (overall #56)
Vite plugins: every listing in weekly downloads order

Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.

Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.

Recent observations

Full history (170)
Recent weekly downloads observations for vite-plugin-lib-inject-css
Date (UTC)Weekly downloadsChange vs. previous
454,101+4.2K
449,896+23.1K
426,797+19.9K
406,912+9.3K
397,576+6K
391,578+93
391,485-1.3K
392,801-2.5K
395,332-19.6K
414,974-20.4K
435,351-12K
447,301+1.4K
445,853-617
446,470—

Similar npm Vite plugins plugins

All 20 vite-plugin-lib-inject-css alternatives

Data source

Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.

Listing: https://www.npmjs.com/package/vite-plugin-lib-inject-css. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.