Skip to content

Commit dfa989a

Browse files
RomainMazBatinux
andauthoredMay 5, 2021
feat: Update tailwind to 2.1 to natively support JIT (#326)
* update tw to natively support jit * Update docs for jit activation * Update jit presentation link to the blog's one * Update 2.setup.md * chore: update pr * chore: update dependencies Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
1 parent 42c23c8 commit dfa989a

10 files changed

+53118
-181
lines changed
 

‎docs/content/2.setup.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,21 @@ Discover your color palette based on your Tailwind config with the [Tailwind vie
8484
8585
## Tailwind Just-In-Time
8686
87-
Tailwind recently released [@tailwindcss/jit](https://github.com/tailwindlabs/tailwindcss-jit) to make the web development much faster.
87+
Tailwind recently released [@tailwindcss/jit](https://blog.tailwindcss.com/just-in-time-the-next-generation-of-tailwind-css) to make the web development much faster.
8888
89-
To activate the option, set `jit: true` in your `nuxt.config.js`:
89+
To activate the option:
90+
- create and modify your custom `tailwind.config.js` as mentioned in [the tailwind's documentation](https://tailwindcss.com/docs/just-in-time-mode#enabling-jit-mode)
91+
- then override the purge config directly into the `tailwind.config.js` file to select the file to want to watch
9092

91-
```ts [nuxt.config.js]
92-
export default {
93-
tailwindcss: {
94-
jit: true
95-
}
93+
94+
```ts [tailwind.config.js]
95+
module.exports = {
96+
mode: 'jit'
9697
}
9798
```
9899

100+
_The double tilde to mention the Nuxt config file is an alias to the root directory which could be different from the sources directory._
101+
99102
Restart your Nuxt server and see how fast it is now ⚡️
100103

101104
## Tailwind Files

‎docs/content/3.options.md

-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export default {
1313
tailwindcss: {
1414
cssPath: '~/assets/css/tailwind.css',
1515
configPath: 'tailwind.config.js',
16-
jit: false,
1716
exposeConfig: false,
1817
config: {}
1918
}
@@ -64,18 +63,6 @@ export default {
6463
}
6564
```
6665

67-
## `jit`
68-
69-
- Default: `false`
70-
71-
Activate Tailwind Just-In-Time package, learn more on https://github.com/tailwindlabs/tailwindcss-jit
72-
73-
When enabled, you should see this in your console when running `nuxt dev`:
74-
75-
```bash
76-
ℹ Tailwind JIT activated
77-
```
78-
7966
## `exposeConfig`
8067

8168
If you need resolved tailwind config in runtime, you can enable exposeConfig option in nuxt.config:

‎docs/content/tailwind/1.config.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ category: Tailwind CSS
1616
plugins: [],
1717
purge: {
1818
content: [
19-
'components/**/*.vue',
20-
'layouts/**/*.vue',
21-
'pages/**/*.vue',
22-
'plugins/**/*.js',
23-
'nuxt.config.js',
24-
// TypeScript
25-
'plugins/**/*.ts',
26-
'nuxt.config.ts'
19+
`components/**/*.{vue,js}`,
20+
`layouts/**/*.vue`,
21+
`pages/**/*.vue`,
22+
`plugins/**/*.{js,ts}`,
23+
`nuxt.config.{js,ts}`
2724
]
2825
}
2926
}

‎example/nuxt.config.js

-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ export default {
44
buildModules: [
55
tailwindModule
66
],
7-
87
components: true,
9-
108
tailwindcss: {
119
jit: true,
1210
exposeConfig: true

‎example/tailwind.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export default {
2+
mode: 'jit'
23
}

‎package-lock.json

+52,926
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@
2727
"@nuxt/postcss8": "^1.1.3",
2828
"@tailwindcss/jit": "^0.1.18",
2929
"autoprefixer": "^10.2.5",
30-
"chalk": "^4.1.0",
30+
"chalk": "^4.1.1",
3131
"clear-module": "^4.1.1",
3232
"consola": "^2.15.3",
33-
"defu": "^3.2.2",
34-
"postcss": "^8.2.9",
33+
"defu": "^4.0.1",
34+
"postcss": "^8.2.13",
3535
"postcss-custom-properties": "^11.0.0",
36-
"postcss-nesting": "^7.0.1",
36+
"postcss-nesting": "^8.0.1",
3737
"tailwind-config-viewer": "^1.5.1",
38-
"tailwindcss": "^2.0.4",
39-
"ufo": "^0.6.10"
38+
"tailwindcss": "^2.1.2",
39+
"ufo": "^0.7.2"
4040
},
4141
"devDependencies": {
42-
"@nuxt/test-utils": "^0.2.1",
42+
"@nuxt/test-utils": "^0.2.2",
4343
"@nuxtjs/eslint-config-typescript": "^6.0.0",
44-
"@types/jest": "^26.0.22",
45-
"codecov": "^3.8.1",
46-
"eslint": "^7.23.0",
44+
"@types/jest": "^26.0.23",
45+
"codecov": "^3.8.2",
46+
"eslint": "^7.25.0",
4747
"jest": "^26.6.3",
4848
"nuxt": "^2.15.4",
49-
"siroc": "^0.8.0",
50-
"standard-version": "^9.1.1"
49+
"siroc": "^0.9.2",
50+
"standard-version": "^9.3.0"
5151
}
5252
}

‎src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ async function tailwindCSSModule (moduleOptions) {
1717
cssPath: join(nuxt.options.dir.assets, 'css', 'tailwind.css'),
1818
exposeConfig: false,
1919
config: defaultTailwindConfig(nuxt.options),
20-
viewer: nuxt.options.dev,
21-
jit: false
20+
viewer: nuxt.options.dev
2221
})
2322

2423
const configPath = nuxt.resolver.resolveAlias(options.configPath)
@@ -79,14 +78,15 @@ async function tailwindCSSModule (moduleOptions) {
7978
// Compute hash
8079
tailwindConfig._hash = String(Date.now())
8180

82-
// Add Tailwind PostCSS plugin
83-
/* istanbul ignore else */
84-
if (options.jit !== false) {
85-
nuxt.options.build.postcss.plugins['@tailwindcss/jit'] = tailwindConfig
81+
if (options.jit === true) {
82+
logger.warn('`tailwindcss.jit` option had been deprecated in favour of `mode: \'jit\'` in `tailwind.config.js`')
83+
tailwindConfig.mode = 'jit'
84+
}
85+
86+
if (tailwindConfig.mode === 'jit') {
8687
logger.info('Tailwind JIT activated')
87-
} else {
88-
nuxt.options.build.postcss.plugins.tailwindcss = tailwindConfig
8988
}
89+
nuxt.options.build.postcss.plugins.tailwindcss = tailwindConfig
9090

9191
/*
9292
** Expose resolved tailwind config as an alias

‎src/tailwind.config.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
// Learn more at https://tailwindcss.com/docs/configuration
2-
export default ({ _dev, rootDir, srcDir }) => ({
2+
export default ({ rootDir, srcDir }) => ({
3+
theme: {
4+
extend: {}
5+
},
6+
variants: {
7+
extend: {}
8+
},
9+
plugins: [],
310
purge: {
411
content: [
512
`${srcDir}/components/**/*.{vue,js}`,
613
`${srcDir}/layouts/**/*.vue`,
714
`${srcDir}/pages/**/*.vue`,
815
`${srcDir}/plugins/**/*.{js,ts}`,
916
`${rootDir}/nuxt.config.{js,ts}`
10-
],
11-
// https://tailwindcss.com/docs/optimizing-for-production#purge-css-options
12-
options: {}
13-
},
14-
theme: {
15-
extend: {}
16-
},
17-
variants: {
18-
extend: {}
19-
},
20-
plugins: []
17+
]
18+
}
2119
})

‎yarn.lock

+146-119
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.