schelmo/windicss-webpack-plugin

๐Ÿƒ Windi CSS for webpack โšก

โ˜… 0Forks 0JavaScriptGitHub โ†—Compare

README

windicss-webpack-plugin

Windi CSS for webpack, it's fast! โšก๏ธ
a.k.a On-demand Tailwind CSS

โšก๏ธ See speed comparison with Tailwind

Features

  • โšก๏ธ It's FAST - 20~100x times faster than Tailwind on webpack apps
  • ๐Ÿงฉ On-demand CSS utilities (Compatible with Tailwind CSS v2)
  • ๐Ÿ“ฆ On-demand native elements style reseting
  • ๐Ÿ”ฅ Hot module replacement (HMR)
  • ๐Ÿƒ Load configurations from tailwind.config.js
  • ๐Ÿค Framework-agnostic - Vue, React, Svelte and vanilla!
  • ๐Ÿ“„ CSS @apply / @screen directives transforms (also works for Vue SFC's <style>)
  • ๐ŸŽณ Support Utility Groups - e.g. bg-gray-200 hover:(bg-gray-100 text-red-300)

Install

yarn add windicss-webpack-plugin -D 
# npm i windicss-webpack-plugin -D

webpack.config.js

If you have access to modify the webpack.config.js directly, then you can do the following.

// webpack.config.js
import WebpackWindiCSSPlugin from 'windicss-webpack-plugin'

export default {
  // ...
  plugins: [
    new WindiCSSWebpackPlugin()
  ],
};
// main.js
import 'windi.css'

Other examples

See ./example

That's all. Build your app just like what you would do with Tailwind CSS, but much faster! โšก๏ธ

Migration

If you are already using Tailwind CSS for your app, please consult the documentation on migrating.

All set.

That's all, fire up your app and enjoy the speed!

TypeScript

You can use TypeScript for your config file if you're using esbuild.

Simply rename your config it to tailwind.config.ts.

// tailwind.config.ts
import { defineConfig } from 'windicss-webpack-plugin'

export default defineConfig({
  darkMode: 'class',
  theme: {
    extend: {
      colors: {
        teal: {
          100: '#096',
        },
      },
    },
  },
})

Configuration

See options.ts for configuration reference.

Caveats

Scoped Style

You will need to set transformCSS: 'pre' to get it work.

@media directive with scoped style can only works with css postcss scss but not sass, less nor stylus

Credits

  • Windy team
  • @antfu Based on his Rollup / Vite implementation & his util package

License

MIT License ยฉ 2021 Harlan Wilton