Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): introduce --tailwind flag #46927

Merged
merged 30 commits into from Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9e98880
chore(cli): add `--tailwind` flag
balazsorban44 Mar 8, 2023
ea9c44b
feat(cli) init app+ts+tw template
balazsorban44 Mar 8, 2023
9c05ff5
convert more styles
balazsorban44 Mar 10, 2023
4489bb1
more styling
balazsorban44 Mar 13, 2023
ea9550e
add top padding
balazsorban44 Mar 13, 2023
dabdb68
remove unnecessary files
balazsorban44 Mar 13, 2023
e535038
add app+js+tailwind
balazsorban44 Mar 13, 2023
5ec3f3e
chore(examples): deprecate Tailwind CSS in favor of CLI
balazsorban44 Mar 13, 2023
ef6503f
add to docs
balazsorban44 Mar 13, 2023
fe063c9
add pages templates
balazsorban44 Mar 14, 2023
3e19f21
Merge branch 'canary' into feat/tailwind-option-cli
balazsorban44 Mar 14, 2023
39e3b4c
sync readmes
balazsorban44 Mar 14, 2023
40e2035
Update README.md
balazsorban44 Mar 14, 2023
7a9a75d
Update README.md
balazsorban44 Mar 14, 2023
5f0f1bd
make sure correct files are copied
balazsorban44 Mar 14, 2023
cbcc758
clarify docs
balazsorban44 Mar 14, 2023
cac033b
update tests
balazsorban44 Mar 14, 2023
bdeb4f7
fix tests
balazsorban44 Mar 14, 2023
313434f
fix more tests
balazsorban44 Mar 14, 2023
1ac54e6
add tests
balazsorban44 Mar 14, 2023
722e203
Merge branch 'canary' into feat/tailwind-option-cli
balazsorban44 Mar 14, 2023
07821c4
apply suggestions from review
balazsorban44 Mar 15, 2023
c8bd101
Merge remote-tracking branch 'origin/feat/tailwind-option-cli' into f…
balazsorban44 Mar 15, 2023
4d4cd91
fix classnames
balazsorban44 Mar 15, 2023
ccea715
add tailwind prettier plugin
balazsorban44 Mar 15, 2023
1424900
run prettier
balazsorban44 Mar 15, 2023
e005159
precompile
balazsorban44 Mar 15, 2023
b2f8311
fix test
balazsorban44 Mar 15, 2023
5700221
remove outdated Tailwind tests
balazsorban44 Mar 15, 2023
03fac6f
Merge branch 'canary' into feat/tailwind-option-cli
balazsorban44 Mar 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/api-reference/create-next-app.md
Expand Up @@ -45,9 +45,17 @@ Options:

Initialize as a JavaScript project.

--tailwind

Initialize with Tailwind CSS config. (default)

--no-tailwind

Initialize without Tailwind CSS config.
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved

--eslint

Initialize with eslint config.
Initialize with ESLint config.

--experimental-app

Expand Down
18 changes: 5 additions & 13 deletions examples/with-tailwindcss/README.md
@@ -1,27 +1,19 @@
# Next.js + Tailwind CSS Example

This example shows how to use [Tailwind CSS](https://tailwindcss.com/) [(v3.2)](https://tailwindcss.com/blog/tailwindcss-v3-2) with Next.js. It follows the steps outlined in the official [Tailwind docs](https://tailwindcss.com/docs/guides/nextjs).

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-tailwindcss)

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-tailwindcss&project-name=with-tailwindcss&repository-name=with-tailwindcss)
Tailwind CSS is integrated into the `create-next-app` CLI, which supports TypeScript and JavaScript, as well as the App Router (`app/`) and the pages directory `pages/`.

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap a project preconfigured with Tailwind CSS:

```bash
npx create-next-app --example with-tailwindcss with-tailwindcss-app
npx create-next-app --tailwind with-tailwindcss-app
```

```bash
yarn create next-app --example with-tailwindcss with-tailwindcss-app
yarn create next-app --tailwind with-tailwindcss-app
```

```bash
pnpm create next-app --example with-tailwindcss with-tailwindcss-app
pnpm create next-app --tailwind with-tailwindcss-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
22 changes: 0 additions & 22 deletions examples/with-tailwindcss/package.json

This file was deleted.

8 changes: 0 additions & 8 deletions examples/with-tailwindcss/pages/_app.tsx

This file was deleted.

86 changes: 0 additions & 86 deletions examples/with-tailwindcss/pages/index.tsx

This file was deleted.

Binary file removed examples/with-tailwindcss/public/favicon.ico
Binary file not shown.
4 changes: 0 additions & 4 deletions examples/with-tailwindcss/public/vercel.svg

This file was deleted.

3 changes: 0 additions & 3 deletions examples/with-tailwindcss/styles/globals.css

This file was deleted.

12 changes: 0 additions & 12 deletions examples/with-tailwindcss/tailwind.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -214,7 +214,7 @@
"styled-jsx": "5.1.1",
"styled-jsx-plugin-postcss": "3.0.2",
"swr": "^2.0.0",
"tailwindcss": "1.1.3",
"tailwindcss": "3.2.7",
"taskr": "1.1.0",
"tree-kill": "1.2.2",
"ts-node": "10.9.1",
Expand Down
11 changes: 10 additions & 1 deletion packages/create-next-app/create-app.ts
Expand Up @@ -34,6 +34,7 @@ export async function createApp({
example,
examplePath,
typescript,
tailwind,
eslint,
experimentalApp,
srcDir,
Expand All @@ -44,14 +45,21 @@ export async function createApp({
example?: string
examplePath?: string
typescript: boolean
tailwind: boolean
eslint: boolean
experimentalApp: boolean
srcDir: boolean
importAlias: string
}): Promise<void> {
let repoInfo: RepoInfo | undefined
const mode: TemplateMode = typescript ? 'ts' : 'js'
const template: TemplateType = experimentalApp ? 'app' : 'default'
const template: TemplateType = experimentalApp
? tailwind
? 'app-tw'
: 'app'
: tailwind
? 'default-tw'
: 'default'

if (example) {
let repoUrl: URL | undefined
Expand Down Expand Up @@ -222,6 +230,7 @@ export async function createApp({
mode,
packageManager,
isOnline,
tailwind,
eslint,
srcDir,
importAlias,
Expand Down
43 changes: 36 additions & 7 deletions packages/create-next-app/index.ts
Expand Up @@ -50,6 +50,13 @@ const program = new Commander.Command(packageJson.name)
`

Initialize as a JavaScript project.
`
)
.option(
'--tailwind',
`

Initialize with Tailwind CSS config. (default)
`
)
.option(
Expand Down Expand Up @@ -222,14 +229,12 @@ async function run(): Promise<void> {
const defaults: typeof preferences = {
typescript: true,
eslint: true,
tailwind: true,
srcDir: false,
importAlias: '@/*',
}
const getPrefOrDefault = (field: string) => {
return typeof preferences[field] === 'undefined'
? defaults[field]
: preferences[field]
}
const getPrefOrDefault = (field: string) =>
preferences[field] ?? defaults[field]

if (!program.typescript && !program.javascript) {
if (ciInfo.isCI) {
Expand All @@ -238,7 +243,7 @@ async function run(): Promise<void> {
program.typescript = false
program.javascript = true
} else {
const styledTypeScript = chalk.hex('#007acc')('TypeScript')
const styledTypeScript = chalk.hex('#0645ad')('TypeScript')
const { typescript } = await prompts(
{
type: 'toggle',
Expand Down Expand Up @@ -275,7 +280,7 @@ async function run(): Promise<void> {
if (ciInfo.isCI) {
program.eslint = true
} else {
const styledEslint = chalk.hex('#007acc')('ESLint')
const styledEslint = chalk.hex('#4b32c3')('ESLint')
const { eslint } = await prompts({
onState: onPromptState,
type: 'toggle',
Expand All @@ -290,6 +295,28 @@ async function run(): Promise<void> {
}
}

if (
!process.argv.includes('--tailwind') &&
!process.argv.includes('--no-tailwind')
) {
if (ciInfo.isCI) {
program.tailwind = false
} else {
const tw = chalk.hex('#38BDF8')('Tailwind CSS')
const { tailwind } = await prompts({
onState: onPromptState,
type: 'toggle',
name: 'tailwind',
message: `Would you like to use ${tw} with this project?`,
initial: getPrefOrDefault('tailwind'),
active: 'Yes',
inactive: 'No',
})
program.tailwind = Boolean(tailwind)
preferences.tailwind = Boolean(tailwind)
}
}

if (
!process.argv.includes('--src-dir') &&
!process.argv.includes('--no-src-dir')
Expand Down Expand Up @@ -367,6 +394,7 @@ async function run(): Promise<void> {
example: example && example !== 'default' ? example : undefined,
examplePath: program.examplePath,
typescript: program.typescript,
tailwind: program.tailwind,
eslint: program.eslint,
experimentalApp: program.experimentalApp,
srcDir: program.srcDir,
Expand Down Expand Up @@ -395,6 +423,7 @@ async function run(): Promise<void> {
packageManager,
typescript: program.typescript,
eslint: program.eslint,
tailwind: program.tailwind,
experimentalApp: program.experimentalApp,
srcDir: program.srcDir,
importAlias: program.importAlias,
Expand Down
4 changes: 3 additions & 1 deletion packages/create-next-app/package.json
Expand Up @@ -26,7 +26,8 @@
"release": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
"prepublishOnly": "cd ../../ && turbo run build",
"build": "pnpm release",
"test-pack": "cd ../../ && pnpm test-pack create-next-app"
"test-pack": "cd ../../ && pnpm test-pack create-next-app",
"lint-fix": "pnpm prettier -w --plugin prettier-plugin-tailwindcss 'templates/*-tw/{ts,js}/{app,pages}/**/*.{js,ts,tsx}'"
},
"devDependencies": {
"@types/async-retry": "1.4.2",
Expand All @@ -48,6 +49,7 @@
"cross-spawn": "6.0.5",
"glob": "8.0.3",
"got": "10.7.0",
"prettier-plugin-tailwindcss": "0.2.4",
"prompts": "2.1.0",
"tar": "4.4.10",
"update-check": "1.5.4",
Expand Down
36 changes: 36 additions & 0 deletions packages/create-next-app/templates/app-tw/js/README-template.md
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file.

[http://localhost:3000/api/hello](http://localhost:3000/api/hello) is an endpoint that uses [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers). This endpoint can be edited in `app/api/hello/route.js`.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
@@ -0,0 +1,3 @@
export async function GET(request: Request) {
return new Response('Hello, Next.js!')
}
Binary file not shown.