File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ const { joinURL, withTrailingSlash } = require('ufo')
7
7
8
8
const logger = require ( './logger' )
9
9
const defaultTailwindConfig = require ( './files/tailwind.config.js' )
10
+ const isInstalled = ( pkg , requireModule = require ) => {
11
+ try {
12
+ requireModule ( pkg )
13
+ return true
14
+ } catch ( e ) {
15
+ return false
16
+ }
17
+ }
10
18
11
19
module . exports = async function ( moduleOptions ) {
12
20
const { nuxt } = this
@@ -25,7 +33,6 @@ module.exports = async function (moduleOptions) {
25
33
// https://tailwindcss.com/docs/using-with-preprocessors#future-css-features
26
34
nuxt . options . build . postcss = defu ( nuxt . options . build . postcss , {
27
35
plugins : {
28
- tailwindcss : { } ,
29
36
'postcss-nested' : { } ,
30
37
'postcss-custom-properties' : { }
31
38
}
@@ -71,7 +78,15 @@ module.exports = async function (moduleOptions) {
71
78
72
79
// Set tailwindcss config
73
80
await nuxt . callHook ( 'tailwindcss:config' , tailwindConfig )
74
- nuxt . options . build . postcss . plugins . tailwindcss = tailwindConfig
81
+
82
+ // Add Tailwind PostCSS plugin
83
+ const postcss = nuxt . options . build . postcss
84
+ if ( isInstalled ( '@tailwindcss/jit' , nuxt . resolver . requireModule ) ) {
85
+ postcss . plugins [ '@tailwindcss/jit' ] = tailwindConfig
86
+ logger . info ( 'Tailwind JIT activated' )
87
+ } else {
88
+ postcss . plugins . tailwindcss = tailwindConfig
89
+ }
75
90
76
91
/*
77
92
** Expose resolved tailwind config as an alias
Original file line number Diff line number Diff line change 25
25
" lib"
26
26
],
27
27
"dependencies" : {
28
+ "@nuxt/postcss8" : " ^1.1.3" ,
28
29
"autoprefixer" : " ^10.2.4" ,
29
30
"chalk" : " ^4.1.0" ,
30
31
"clear-module" : " ^4.1.1" ,
31
32
"consola" : " ^2.15.3" ,
32
33
"defu" : " ^3.2.2" ,
33
34
"fs-extra" : " ^9.1.0" ,
34
- "@nuxt/postcss8" : " ^1.1.3" ,
35
35
"postcss" : " ^8.2.7" ,
36
36
"postcss-nested" : " ^5.0.5" ,
37
37
"tailwind-config-viewer" : " ^1.5.0" ,
You can’t perform that action at this time.
0 commit comments