You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vite-plugin-lib-css-injection

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-lib-css-injection

A vite plugin that would inject the css file into your bundled js file.

1.0.5
Source
npmnpm
Version published
Weekly downloads
7
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-lib-css-injection

An enhancement vite plugin of vite-plugin-libcss that would inject the css file into your bundled js file.

Note

Only support for ESM and library-mode

Install

pnpm install vite-plugin-lib-css-injection --save -D

Usage

ESM

import libCss from 'vite-plugin-lib-css-injection'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [libCss()],
  build: {
    lib: {
      entry: path.resolve(__dirname, './src/main.ts'),
    },
    rollupOptions: {
      output: [
        {
          dir: 'dist/esm',
          format: 'es',
          entryFileNames: 'index.js',
        }
      ],
    },
  },
})

build result like:

// dist/esm/index.js
import "./style.css"
// rest of your bundled js file code

and if there is no rollupOptions but lib.fileName, this plugin will also work!

lib: {
  fileName() {
    return 'esm/index.js'
  }
}

build result like:

// dist/esm/index.js
import "../style.css"
// rest of your bundled js file code

That means this plugin will according to the entry filename to change the relative path of css file.

CJS

// vite.config.js
const libCss = require('vite-plugin-lib-css-injection')

module.exports = {
  plugins: [libCss()]
}

Keywords

vite

FAQs

Package last updated on 04 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts