nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.29k stars 519 forks source link

Output Directory Content Deletion in Dev Mode #2865

Open McSego1990 opened 2 weeks ago

McSego1990 commented 2 weeks ago

Environment

Nitro Version: 2.10.4
Node Version: v20.18.0
Package Manager: pnpm@9.12.3
Operating System: Linux

Reproduction

Steps to Reproduce

  1. Create a new Nuxt 3.14.x project (which uses Nitro 2.10.4)
  2. Run production build: pnpm build
  3. Verify output directory structure:
    .output/
    ├── nitro.json
    ├── public/
    │   ├── _nuxt/
    │   ├── favicon.ico
    │   └── robots.txt
    └── server/
    ├── chunks/
    ├── index.mjs
    └── node_modules/
  4. Start development server: pnpm dev
  5. Observe output directory is minimized to:
    .output/
    ├── public/
    └── server/
    ├── index.mjs
    └── index.mjs.map

Expected Behavior

Current Behavior

Workaround

We found a temporary workaround by separating development and production output directories:

{
  output: {
    dir: process.env.NODE_ENV === "development" ? ".output-dev" : ".output",
    serverDir: process.env.NODE_ENV === "development" 
      ? ".output-dev/server" 
      : ".output/server",
    publicDir: process.env.NODE_ENV === "development" 
      ? ".output-dev/public" 
      : ".output/public"
  }
}

Describe the bug

When using Nitro (via Nuxt 3.14.x), the production build output directory content is unexpectedly deleted or minimized when starting the development server. This issue was identified after observing the behavior in Nuxt 3.14.x and was traced back to Nitro's handling of the output directory.

However, this is suboptimal as:

  1. Development environment shouldn't need to affect production build output
  2. Creating a separate output directory for development seems unnecessary
  3. This behavior changed between Nitro versions (works correctly in older versions)

Technical Details

Questions

  1. Is this an intended change in behavior?
  2. Is there a proper way to preserve production build output while running development server?
  3. Should we consider adding a configuration option to prevent development mode from cleaning production build files?

Additional context

No response

Logs

No response