UNPKG

4.45 kBMarkdownView Raw
1<p align="center"><img src="https://user-images.githubusercontent.com/904724/59274615-fcef5780-8c5a-11e9-8b17-5c4915895144.png" alt="tailwindcss-module" width="500"/></p>
2<p align="center">
3 <a href="https://npmjs.com/package/@nuxtjs/tailwindcss"><img src="https://img.shields.io/npm/v/@nuxtjs/tailwindcss/latest.svg" alt="npm downloads"></a>
4 <a href="https://npmjs.com/package/@nuxtjs/tailwindcss"><img src="https://img.shields.io/npm/dt/@nuxtjs/tailwindcss.svg" alt="npm version"></a>
5 <a href="https://github.com/nuxt-community/tailwindcss-module/actions?query=workflow%3Aci"><img src="https://github.com/nuxt-community/tailwindcss-module/workflows/ci/badge.svg" alt="github ci"></a>
6 <a href="https://codecov.io/gh/nuxt-community/tailwindcss-module"><img src="https://img.shields.io/codecov/c/github/nuxt-community/tailwindcss-module.svg" alt="coverage"></a>
7 <a href="https://www.npmjs.com/package/@nuxtjs/tailwindcss"><img src="https://badgen.net/npm/license/@nuxtjs/tailwindcss" alt="License"></a>
8</p>
9
10> [Tailwind CSS](https://tailwindcss.com) module for [NuxtJS](https://nuxtjs.org) with [modern css](https://tailwindcss.com/docs/using-with-preprocessors#future-css-features) ⚡ī¸
11
12## Infos
13
14- 📖 [Release Notes](https://github.com/nuxt-community/tailwindcss-module/releases)
15- 🏀 [Online playground](https://codesandbox.io/s/o4vn5pvp7q)
16- đŸŒŋ [CSS Nesting Module Draft](https://drafts.csswg.org/css-nesting-1/)
17- 📐 [Display your breakpoints with nuxt-breaky](https://github.com/teamnovu/nuxt-breaky)
18- 🌓 [Dark mode example](https://codesandbox.io/s/nuxt-dark-tailwindcss-17g2j?file=/tailwind.config.js) with [tailwindcss-dark-mode](https://github.com/ChanceArthur/tailwindcss-dark-mode) and [@nuxtjs/color-mode](https://github.com/nuxt-community/color-mode-module)
19
20## Setup
21
221. Add `@nuxtjs/tailwindcss` dependency to your project
23```bash
24npm install --save-dev @nuxtjs/tailwindcss # or yarn add --dev @nuxtjs/tailwindcss
25```
26
272. Add `@nuxtjs/tailwindcss` to the `buildModules` section of `nuxt.config.js`
28
29```js
30{
31 buildModules: [
32 '@nuxtjs/tailwindcss'
33 ]
34}
35```
36
37ℹī¸ If you are using `nuxt < 2.9.0`, use `modules` property instead.
38
39## Usage
40
41This module will automatically create two files in your [srcDir](https://nuxtjs.org/api/configuration-srcdir):
42- `~/tailwind.config.js`
43- `~/assets/css/tailwind.css`
44
45It will also inject the CSS file globally and configure the [purge option](https://tailwindcss.com/docs/controlling-file-size#removing-unused-css) and [postcss-preset-env](https://preset-env.cssdb.org) to [stage 1](https://preset-env.cssdb.org/features#stage-1).
46
47## Configuration
48
49If you want to set a different path for the configuration file or css file, you can use these given options:
50
51```js
52// nuxt.config.js
53{
54 buildModules: [
55 '@nuxtjs/tailwindcss'
56 ],
57 tailwindcss: {
58 configPath: '~/config/tailwind.config.js',
59 cssPath: '~/assets/css/tailwind.css',
60 exposeConfig: false
61 }
62}
63```
64
65To enable purgeCSS in development, set `purge.enabled: true` in `tailwind.config.js`, be careful that it will slow down your development process. Learn more on [removing unused CSS](https://tailwindcss.com/docs/controlling-file-size#removing-unused-css).
66
67## Referencing in JavaScript
68
69It can often be useful to reference tailwind configuration values in runtime. For example to access some of your theme values when dynamically applying inline styles in a component.
70
71If you need resolved tailwind config in runtime, you can enable `exposeConfig` option in `nuxt.config`:
72
73```js
74// nuxt.config.js
75{
76 tailwindcss: {
77 exposeConfig: true
78 }
79}
80```
81
82Then import where needed from `~tailwind.config`:
83
84```js
85// Import fully resolved config
86import tailwindConfig from '~tailwind.config'
87
88 // Import only part which is required to allow tree-shaking
89import { theme } from '~tailwind.config'
90```
91
92**NOTE:** Please be aware this adds **~19.5KB (~3.5KB)** to the client bundle size.
93
94## Contributing
95
96You can contribute to this module online with CodeSandBox:
97
98[![Edit @nuxtjs/tailwindcss](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/nuxt-community/tailwindcss-module/tree/master/?fontsize=14&hidenavigation=1&theme=dark)
99
100Or locally:
101
1021. Clone this repository
1032. Install dependencies using `yarn install` or `npm install`
1043. Start development server using `yarn dev` or `npm run dev`
105
106## License
107
108[MIT License](./LICENSE)
109
110Copyright (c) Nuxt.js Team