Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vite-plugin-libcss

wxsms27.6kMIT1.1.1TypeScript support: included

This plugin will inject css into bundled js file using import statement.

vite, plugin, lib, css

readme

vite-plugin-libcss

This plugin will inject css into bundled js file using import statement like this:

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

Install:

npm i vite-plugin-libcss -D

Usage:

// vite.config.js
import libCss from 'vite-plugin-libcss';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // any other plugins
    libCss()
  ],
});

or with include/exclude options

// vite.config.js
import libCss from 'vite-plugin-libcss';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // any other plugins
    libCss({
      include: 'src/**/*', // Include all entry files
      exclude: 'src/utils/*', // Exclude entry files in the "utils" directory
    })
  ],
});

Note that this plugin will only work with library-mode and es format build.