Skip to content

Commit 9231acf

Browse files
committed
Update to Tailwind v3
As per vercel/next.js@4d4f309
1 parent 84feea5 commit 9231acf

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/main/setup/steps/add-content/generate-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ const getMaterialUIImports = ({ flags }: ValidCNSInputs) => {
9797

9898
const getTailwindCssImport = ({ flags }: ValidCNSInputs) => {
9999
return flags.styling === "tailwind-css"
100-
? /* tsx */ `import "tailwindcss/tailwind.css";`
100+
? /* tsx */ `import '../styles/globals.css';`
101101
: ""
102102
}

src/main/setup/steps/set-up-tailwind-css.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import endent from "endent"
2+
import { promises as fs } from "fs"
23
import { writeFile } from "../../helpers/io"
34
import { install, packages } from "../packages"
45
import { Step } from "../step"
56

7+
/**
8+
* Follows a combination of the official Next.js template:
9+
* https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss
10+
* and the official Tailwind guide for Next.js:
11+
* https://tailwindcss.com/docs/guides/nextjs
12+
*/
613
export const setUpTailwindCssStep: Step = {
714
description: "setting up Tailwind CSS",
815

@@ -19,31 +26,33 @@ export const setUpTailwindCssStep: Step = {
1926

2027
await addTailwindConfig()
2128
await addPostcssConfig()
29+
await addStylesGlobalsCss()
2230
},
2331
}
2432

2533
const addTailwindConfig = async () => {
34+
// From running `npx tailwind init -p --types` and adding globs to the content array according to https://tailwindcss.com/docs/guides/nextjs
2635
const tailwindConfigString = endent/* js */ `
27-
module.exports = {
28-
mode: 'jit',
29-
purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
30-
darkMode: false, // or 'media' or 'class'
36+
/** @type {import('tailwindcss/types').Config} */
37+
const config = {
38+
content: [
39+
'./pages/**/*.{js,ts,jsx,tsx}',
40+
'./components/**/*.{js,ts,jsx,tsx}',
41+
],
3142
theme: {
3243
extend: {},
3344
},
34-
variants: {
35-
extend: {},
36-
},
3745
plugins: [],
3846
}
47+
48+
module.exports = config;
3949
`
4050
await writeFile("tailwind.config.js", tailwindConfigString)
4151
}
4252

4353
const addPostcssConfig = async () => {
54+
// From https://github.com/vercel/next.js/blob/canary/examples/with-tailwindcss/postcss.config.js
4455
const postcssConfigString = endent/* js */ `
45-
// If you want to use other PostCSS plugins, see the following:
46-
// https://tailwindcss.com/docs/using-with-preprocessors
4756
module.exports = {
4857
plugins: {
4958
tailwindcss: {},
@@ -53,3 +62,14 @@ const addPostcssConfig = async () => {
5362
`
5463
await writeFile("postcss.config.js", postcssConfigString)
5564
}
65+
66+
const addStylesGlobalsCss = async () => {
67+
// From https://github.com/vercel/next.js/blob/canary/examples/with-tailwindcss/styles/globals.css
68+
const stylesGlobalsCssString = endent/* css */ `
69+
@tailwind base;
70+
@tailwind components;
71+
@tailwind utilities;
72+
`
73+
await fs.mkdir("styles", { recursive: true })
74+
await writeFile("styles/globals.css", stylesGlobalsCssString)
75+
}

0 commit comments

Comments
 (0)