Skip to content

Commit 8ab33b8

Browse files
authored
feat!: upgrade to tailwindcss@2 (#270)
1 parent 0a5c1ea commit 8ab33b8

File tree

10 files changed

+1750
-1036
lines changed

10 files changed

+1750
-1036
lines changed

example/components/CallToAction.vue

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<!-- This example requires Tailwind CSS v2.0+ -->
3+
<div class="bg-gray-50">
4+
<div class="px-4 py-12 mx-auto max-w-7xl sm:px-6 lg:py-16 lg:px-8 lg:flex lg:items-center lg:justify-between">
5+
<h2 class="text-3xl font-extrabold tracking-tight text-gray-900 sm:text-4xl">
6+
<span class="block">Ready to dive in?</span>
7+
<span class="block text-indigo-600">Start your free trial today.</span>
8+
</h2>
9+
<div class="flex mt-8 lg:mt-0 lg:flex-shrink-0">
10+
<div class="inline-flex rounded-md shadow">
11+
<a href="#" class="inline-flex items-center justify-center px-5 py-3 text-base font-medium text-white bg-indigo-600 border border-transparent rounded-md hover:bg-indigo-700">
12+
Get started
13+
</a>
14+
</div>
15+
<div class="inline-flex ml-3 rounded-md shadow">
16+
<a href="#" class="inline-flex items-center justify-center px-5 py-3 text-base font-medium text-indigo-600 bg-white border border-transparent rounded-md hover:bg-indigo-50">
17+
Learn more
18+
</a>
19+
</div>
20+
</div>
21+
</div>
22+
</div>
23+
</template>

example/nuxt.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default {
44
buildModules: [
55
tailwindModule
66
],
7+
components: true,
78
tailwindcss: {
89
exposeConfig: true
910
}

example/pages/index.vue

+4-37
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
11
<template>
22
<div>
3-
<div class="banner">
4-
<div
5-
class="p-2 bg-indigo-800 items-center text-indigo-100 leading-none lg:rounded-full flex lg:inline-flex"
6-
role="alert"
7-
>
8-
<span
9-
class="flex rounded-full bg-indigo-500 uppercase px-2 py-1 text-xs font-bold mr-3"
10-
>New</span>
11-
<span
12-
class="font-semibold mr-2 text-left flex-auto"
13-
>Get the coolest t-shirts from our brand new store</span>
14-
<svg
15-
class="fill-current opacity-75 h-4 w-4"
16-
xmlns="http://www.w3.org/2000/svg"
17-
viewBox="0 0 20 20"
18-
>
19-
<path
20-
d="M12.95 10.707l.707-.707L8 4.343 6.586 5.757 10.828 10l-4.242 4.243L8 15.657l4.95-4.95z"
21-
/>
22-
</svg>
23-
</div>
3+
<div>
4+
<CallToAction />
245
</div>
25-
<pre>{{ tailwindConfig }}</pre>
6+
7+
<pre class="p-4 m-4 bg-gray-100 rounded">{{ tailwindConfig }}</pre>
268
</div>
279
</template>
2810

@@ -35,18 +17,3 @@ export default {
3517
}
3618
}
3719
</script>
38-
39-
<style scoped>
40-
.banner {
41-
@apply bg-indigo-900 text-center py-4;
42-
@screen lg {
43-
@apply bg-yellow-500;
44-
}
45-
&:hover {
46-
@apply bg-indigo-800;
47-
@screen lg {
48-
@apply bg-yellow-600;
49-
}
50-
}
51-
}
52-
</style>

lib/files/tailwind.config.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
// Learn more at https://tailwindcss.com/docs/configuration
12
module.exports = ({ dev, rootDir, srcDir }) => ({
2-
theme: {},
3-
variants: {},
4-
plugins: [],
5-
purge: {
6-
// Learn more on https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css
7-
enabled: !dev,
8-
content: [
9-
`${srcDir}/components/**/*.{vue,js}`,
10-
`${srcDir}/layouts/**/*.vue`,
11-
`${srcDir}/pages/**/*.vue`,
12-
`${srcDir}/plugins/**/*.{js,ts}`,
13-
`${rootDir}/nuxt.config.{js,ts}`
14-
]
15-
}
3+
purge: [
4+
`${srcDir}/components/**/*.{vue,js}`,
5+
`${srcDir}/layouts/**/*.vue`,
6+
`${srcDir}/pages/**/*.vue`,
7+
`${srcDir}/plugins/**/*.{js,ts}`,
8+
`${rootDir}/nuxt.config.{js,ts}`
9+
],
10+
darkMode: false, // or 'media' or 'class'
11+
theme: {
12+
extend: {}
13+
},
14+
variants: {
15+
extend: {}
16+
},
17+
plugins: []
1618
})

lib/module.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ module.exports = async function (moduleOptions) {
2121
const configPath = nuxt.resolver.resolveAlias(options.configPath)
2222
const cssPath = nuxt.resolver.resolveAlias(options.cssPath)
2323

24+
// Require postcss@8
25+
await this.addModule('nuxt-postcss8')
26+
2427
// Include CSS file in project css
2528
if (await pathExists(cssPath)) {
2629
logger.info(`Using Tailwind CSS from ~/${relative(nuxt.options.srcDir, cssPath)}`)

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
"lib"
2525
],
2626
"dependencies": {
27+
"autoprefixer": "^10.0.2",
2728
"chalk": "^4.1.0",
2829
"clear-module": "^4.1.1",
2930
"consola": "^2.15.0",
3031
"defu": "^3.2.2",
3132
"fs-extra": "^9.0.1",
32-
"tailwind-config-viewer": "^1.4.0",
33-
"tailwindcss": "^1.9.6",
33+
"nuxt-postcss8": "^1.0.1",
34+
"postcss": "^8.0.9",
35+
"tailwind-config-viewer": "^1.5.0",
36+
"tailwindcss": "^2.0.3",
3437
"ufo": "^0.6.6"
3538
},
3639
"devDependencies": {
@@ -53,7 +56,7 @@
5356
"eslint-plugin-vue": "^7.4.1",
5457
"husky": "^5.1.3",
5558
"jest": "^26.6.3",
56-
"nuxt": "^2.14.12",
59+
"nuxt": "^2.15.2",
5760
"standard-version": "^9.1.0"
5861
}
5962
}

test/config.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('config', () => {
1515
buildModules: [
1616
tailwindModule
1717
],
18+
components: true,
1819
tailwindcss: {
1920
exposeConfig: true,
2021
configPath: join(__dirname, 'mock', 'tailwind.config.js'),
@@ -35,7 +36,7 @@ describe('config', () => {
3536

3637
test('render', async () => {
3738
const html = await get('/')
38-
expect(html).toContain('Get the coolest t-shirts from our brand new store')
39+
expect(html).toContain('Ready to dive in?')
3940
expect(html).not.toContain('.bg-pink-700')
4041
})
4142

@@ -50,7 +51,7 @@ describe('config', () => {
5051
})
5152

5253
test('merged the tailwind default config', () => {
53-
expect(nuxt.options.build.postcss.plugins.tailwindcss.purge.content).toContain(`${rootDir}/nuxt.config.{js,ts}`)
54-
expect(nuxt.options.build.postcss.plugins.tailwindcss.purge.content).toContain('content/**/*.md')
54+
expect(nuxt.options.build.postcss.plugins.tailwindcss.purge).toContain(`${rootDir}/nuxt.config.{js,ts}`)
55+
expect(nuxt.options.build.postcss.plugins.tailwindcss.purge).toContain('content/**/*.md')
5556
})
5657
})

test/mock/tailwind.config.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module.exports = {
2-
purge: {
3-
content: [
4-
'content/**/*.md'
5-
]
6-
}
2+
purge: [
3+
'content/**/*.md'
4+
]
75
}

test/ok.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('ok', () => {
1515
buildModules: [
1616
tailwindModule
1717
],
18+
components: true,
1819
tailwindcss: {
1920
exposeConfig: true
2021
}
@@ -33,7 +34,7 @@ describe('ok', () => {
3334

3435
test('render', async () => {
3536
const html = await get('/')
36-
expect(html).toContain('Get the coolest t-shirts from our brand new store')
37+
expect(html).toContain('Ready to dive in?')
3738
expect(html).not.toContain('.bg-pink-700')
3839
})
3940

0 commit comments

Comments
 (0)