Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

A Vite plugin that injects CSS to JS file in library mode.

License

Notifications You must be signed in to change notification settings

lovelliu/vite-plugin-style-inject

Repository files navigation

vite-plugin-style-inject

attention: I found a better solution to solve this demand, please check out this plugin: vite-plugin-css-injected-by-js

NPM version

English | 中文

The plugin is used to inject CSS into JS files, so there will not generate CSS files. It is mainly used to pack some libraries with fewer styles, for example, A component that has been encapsulated.

The user using the library will not need to import an additional CSS file.

  • Before
import xxxComponent from 'xxx-component';
import 'xxx-component/dist/xxx.css';
  • Now
import xxxComponent from 'xxx-component';

Install

  • npm
npm i vite-plugin-style-inject --save-dev
  • yarn
yarn add -D vite-plugin-style-inject
  • pnpm
pnpm add -D vite-plugin-style-inject

Usage

// vite.config.ts
import { defineConfig } from 'vite';

import VitePluginStyleInject from 'vite-plugin-style-inject';

export default defineConfig({
  plugins: [VitePluginStyleInject()],
  ......
});

License

MIT License © 2022 Name6

About

A Vite plugin that injects CSS to JS file in library mode.

Topics

Resources

License

Stars

Watchers

Forks