Unverified Commit a0ab6d32 authored by Delba de Oliveira's avatar Delba de Oliveira Committed by GitHub

docs: Move `src` folder page to API reference (#78499)

parent 7a64ada1
...@@ -124,7 +124,7 @@ Both `layout.tsx` and `page.tsx` will be rendered when the user visits the root ...@@ -124,7 +124,7 @@ Both `layout.tsx` and `page.tsx` will be rendered when the user visits the root
> **Good to know**: > **Good to know**:
> >
> - If you forget to create the root layout, Next.js will automatically create this file when running the development server with `next dev`. > - If you forget to create the root layout, Next.js will automatically create this file when running the development server with `next dev`.
> - You can optionally use a [`src` directory](/docs/app/building-your-application/configuring/src-directory) in the root of your project to separate your application's code from configuration files. > - You can optionally use a [`src` folder](/docs/app/api-reference/file-conventions/src-folder) in the root of your project to separate your application's code from configuration files.
</AppOnly> </AppOnly>
......
...@@ -25,7 +25,7 @@ Top-level folders are used to organize your application's code and static assets ...@@ -25,7 +25,7 @@ Top-level folders are used to organize your application's code and static assets
| [`app`](/docs/app/building-your-application/routing) | App Router | | [`app`](/docs/app/building-your-application/routing) | App Router |
| [`pages`](/docs/pages/building-your-application/routing) | Pages Router | | [`pages`](/docs/pages/building-your-application/routing) | Pages Router |
| [`public`](/docs/app/building-your-application/optimizing/static-assets) | Static assets to be served | | [`public`](/docs/app/building-your-application/optimizing/static-assets) | Static assets to be served |
| [`src`](/docs/app/building-your-application/configuring/src-directory) | Optional application source folder | | [`src`](/docs/app/api-reference/file-conventions/src-folder) | Optional application source folder |
### Top-level files ### Top-level files
...@@ -285,12 +285,12 @@ Route groups are useful for: ...@@ -285,12 +285,12 @@ Route groups are useful for:
- [Creating multiple nested layouts in the same segment, including multiple root layouts](#creating-multiple-root-layouts) - [Creating multiple nested layouts in the same segment, including multiple root layouts](#creating-multiple-root-layouts)
- [Adding a layout to a subset of routes in a common segment](#opting-specific-segments-into-a-layout) - [Adding a layout to a subset of routes in a common segment](#opting-specific-segments-into-a-layout)
### `src` directory ### `src` folder
Next.js supports storing application code (including `app`) inside an optional [`src` directory](/docs/app/building-your-application/configuring/src-directory). This separates application code from project configuration files which mostly live in the root of a project. Next.js supports storing application code (including `app`) inside an optional [`src` folder](/docs/app/api-reference/file-conventions/src-folder). This separates application code from project configuration files which mostly live in the root of a project.
<Image <Image
alt="An example folder structure with the `src` directory" alt="An example folder structure with the `src` folder"
srcLight="/docs/light/project-organization-src-directory.png" srcLight="/docs/light/project-organization-src-directory.png"
srcDark="/docs/dark/project-organization-src-directory.png" srcDark="/docs/dark/project-organization-src-directory.png"
width="1600" width="1600"
......
...@@ -282,7 +282,7 @@ For example, if `NODE_ENV` is `development` and you define a variable in both `. ...@@ -282,7 +282,7 @@ For example, if `NODE_ENV` is `development` and you define a variable in both `.
## Good to know ## Good to know
- If you are using a [`/src` directory](/docs/app/building-your-application/configuring/src-directory), `.env.*` files should remain in the root of your project. - If you are using a [`/src` directory](/docs/app/api-reference/file-conventions/src-folder), `.env.*` files should remain in the root of your project.
- If the environment variable `NODE_ENV` is unassigned, Next.js automatically assigns `development` when running the `next dev` command, or `production` for all other commands. - If the environment variable `NODE_ENV` is unassigned, Next.js automatically assigns `development` when running the `next dev` command, or `production` for all other commands.
## Version History ## Version History
......
...@@ -82,7 +82,7 @@ A Next.js [App Router](/docs/app) application must include a [root layout](/docs ...@@ -82,7 +82,7 @@ A Next.js [App Router](/docs/app) application must include a [root layout](/docs
The closest equivalent of the root layout file in a CRA application is `public/index.html`, which includes your `<html>`, `<head>`, and `<body>` tags. The closest equivalent of the root layout file in a CRA application is `public/index.html`, which includes your `<html>`, `<head>`, and `<body>` tags.
1. Create a new `app` directory inside your `src` directory (or at your project root if you prefer `app` at the root). 1. Create a new `app` directory inside your `src` folder (or at your project root if you prefer `app` at the root).
2. Inside the `app` directory, create a `layout.tsx` (or `layout.js`) file: 2. Inside the `app` directory, create a `layout.tsx` (or `layout.js`) file:
```tsx filename="app/layout.tsx" switcher ```tsx filename="app/layout.tsx" switcher
......
...@@ -140,7 +140,7 @@ The closest equivalent to the root layout file in a Vite application is the ...@@ -140,7 +140,7 @@ The closest equivalent to the root layout file in a Vite application is the
In this step, you'll convert your `index.html` file into a root layout file: In this step, you'll convert your `index.html` file into a root layout file:
1. Create a new `app` directory in your `src` directory. 1. Create a new `app` directory in your `src` folder.
2. Create a new `layout.tsx` file inside that `app` directory: 2. Create a new `layout.tsx` file inside that `app` directory:
```tsx filename="app/layout.tsx" switcher ```tsx filename="app/layout.tsx" switcher
......
...@@ -13,7 +13,7 @@ Instrumentation is the process of using code to integrate monitoring and logging ...@@ -13,7 +13,7 @@ Instrumentation is the process of using code to integrate monitoring and logging
## Convention ## Convention
To set up instrumentation, create `instrumentation.ts|js` file in the **root directory** of your project (or inside the [`src`](/docs/app/building-your-application/configuring/src-directory) folder if using one). To set up instrumentation, create `instrumentation.ts|js` file in the **root directory** of your project (or inside the [`src`](/docs/app/api-reference/file-conventions/src-folder) folder if using one).
Then, export a `register` function in the file. This function will be called **once** when a new Next.js server instance is initiated. Then, export a `register` function in the file. This function will be called **once** when a new Next.js server instance is initiated.
......
--- ---
title: File Conventions title: File-system conventions
description: API Reference for Next.js File Conventions. description: API Reference for Next.js file-system conventions.
--- ---
...@@ -9,7 +9,7 @@ related: ...@@ -9,7 +9,7 @@ related:
The `instrumentation.js|ts` file is used to integrate observability tools into your application, allowing you to track the performance and behavior, and to debug issues in production. The `instrumentation.js|ts` file is used to integrate observability tools into your application, allowing you to track the performance and behavior, and to debug issues in production.
To use it, place the file in the **root** of your application or inside a [`src` folder](/docs/app/building-your-application/configuring/src-directory) if using one. To use it, place the file in the **root** of your application or inside a [`src` folder](/docs/app/api-reference/file-conventions/src-folder) if using one.
## Exports ## Exports
......
--- ---
title: src Directory title: src Folder
description: Save pages under the `src` directory as an alternative to the root `pages` directory. nav_title: src
description: Save pages under the `src` folder as an alternative to the root `pages` directory.
related: related:
links: links:
- app/getting-started/project-structure - app/getting-started/project-structure
...@@ -8,14 +9,14 @@ related: ...@@ -8,14 +9,14 @@ related:
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
As an alternative to having the special Next.js `app` or `pages` directories in the root of your project, Next.js also supports the common pattern of placing application code under the `src` directory. As an alternative to having the special Next.js `app` or `pages` directories in the root of your project, Next.js also supports the common pattern of placing application code under the `src` folder.
This separates application code from project configuration files which mostly live in the root of a project, which is preferred by some individuals and teams. This separates application code from project configuration files which mostly live in the root of a project, which is preferred by some individuals and teams.
To use the `src` directory, move the `app` Router folder or `pages` Router folder to `src/app` or `src/pages` respectively. To use the `src` folder, move the `app` Router folder or `pages` Router folder to `src/app` or `src/pages` respectively.
<Image <Image
alt="An example folder structure with the `src` directory" alt="An example folder structure with the `src` folder"
srcLight="/docs/light/project-organization-src-directory.png" srcLight="/docs/light/project-organization-src-directory.png"
srcDark="/docs/dark/project-organization-src-directory.png" srcDark="/docs/dark/project-organization-src-directory.png"
width="1600" width="1600"
...@@ -29,6 +30,6 @@ To use the `src` directory, move the `app` Router folder or `pages` Router folde ...@@ -29,6 +30,6 @@ To use the `src` directory, move the `app` Router folder or `pages` Router folde
> - `.env.*` files should remain in the root of your project. > - `.env.*` files should remain in the root of your project.
> - `src/app` or `src/pages` will be ignored if `app` or `pages` are present in the root directory. > - `src/app` or `src/pages` will be ignored if `app` or `pages` are present in the root directory.
> - If you're using `src`, you'll probably also move other application folders such as `/components` or `/lib`. > - If you're using `src`, you'll probably also move other application folders such as `/components` or `/lib`.
> - If you're using Middleware, ensure it is placed inside the `src` directory. > - If you're using Middleware, ensure it is placed inside the `src` folder.
> - If you're using Tailwind CSS, you'll need to add the `/src` prefix to the `tailwind.config.js` file in the [content section](https://tailwindcss.com/docs/content-configuration). > - If you're using Tailwind CSS, you'll need to add the `/src` prefix to the `tailwind.config.js` file in the [content section](https://tailwindcss.com/docs/content-configuration).
> - If you are using TypeScript paths for imports such as `@/*`, you should update the `paths` object in `tsconfig.json` to include `src/`. > - If you are using TypeScript paths for imports such as `@/*`, you should update the `paths` object in `tsconfig.json` to include `src/`.
---
title: File-system conventions
description: API Reference for Next.js file-system conventions.
---
--- ---
title: src Directory title: src Directory
description: Save pages under the `src` directory as an alternative to the root `pages` directory. description: Save pages under the `src` folder as an alternative to the root `pages` directory.
source: app/building-your-application/configuring/src-directory source: app/api-reference/file-conventions/src-folder
--- ---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment