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

Package detail

vite-inject-css

stasadance19MIT3.1.0TypeScript support: included

A Vite plugin that takes the CSS and injects it via JS using CSSStyleSheet.insertRule()

vite, vite-plugin, plugin, typescript, css-injected-by-js, single-js-file, css, js

readme

vite-inject-css

A Vite plugin that takes the CSS and injects it via JS using CSSStyleSheet.insertRule()

This was inspired by React Native's StyleSheet, the <style> tag injected to the header doesn't have anything inside when viewed through inspect element

Installation

yarn add -D vite-inject-css

Usage

import injectCSS from "vite-inject-css";

export default {
    plugins: [injectCSS()],
};

Config

When you add the plugin, you can provide an optional config object.

obfuscate

If you want extra obfuscation of the CSS rules, with the downside of a bigger bundle size, set obfuscate to true

import injectCSS from "vite-inject-css";

export default {
    plugins: [injectCSS({ obfuscate: true })],
};