
Tailwind CSS module for NuxtJS with modern css β‘οΈ
@nuxtjs/tailwindcss dependency to your projectnpm install --save-dev @nuxtjs/tailwindcss # or yarn add --dev @nuxtjs/tailwindcss
@nuxtjs/tailwindcss to the buildModules section of nuxt.config.js{
buildModules: [
'@nuxtjs/tailwindcss'
]
}
βΉοΈ If you are using nuxt < 2.9.0, use modules property instead.
This module will automatically create two files in your srcDir:
~/tailwind.config.js~/assets/css/tailwind.cssIt will also inject the CSS file globally and configure the purge option and postcss-preset-env to stage 1.
If you want to set a different path for the configuration file or css file, you can use these given options:
// nuxt.config.js
{
buildModules: [
'@nuxtjs/tailwindcss'
],
tailwindcss: {
configPath: '~/config/tailwind.config.js',
cssPath: '~/assets/css/tailwind.css',
exposeConfig: false
}
}
To 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.
It 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.
If you need resolved tailwind config in runtime, you can enable exposeConfig option in nuxt.config:
// nuxt.config.js
{
tailwindcss: {
exposeConfig: true
}
}
Then import where needed from ~tailwind.config:
// Import fully resolved config
import tailwindConfig from '~tailwind.config'
// Import only part which is required to allow tree-shaking
import { theme } from '~tailwind.config'
undefinedNOTE: Please be aware this adds ~19.5KB (~3.5KB) to the client bundle size.
You can contribute to this module online with CodeSandBox:
Or locally:
yarn install or npm installyarn dev or npm run devCopyright Β© Nuxt.js Team
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.