11import endent from "endent"
2+ import { promises as fs } from "fs"
23import { writeFile } from "../../helpers/io"
34import { install , packages } from "../packages"
45import { 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+ */
613export 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
2533const 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
4353const 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