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

Feature: Add Option to Skip Initial Build in Watch Mode #4046

Open
hichemfantar opened this issue Jan 23, 2025 · 0 comments
Open

Feature: Add Option to Skip Initial Build in Watch Mode #4046

hichemfantar opened this issue Jan 23, 2025 · 0 comments

Comments

@hichemfantar
Copy link

hichemfantar commented Jan 23, 2025

Problem

When running a development script like the following:

"dev": "npm run build && concurrently \"npm run build --watch\" \"npm run serve\""
  await esbuild.build({
    watch: {
      skipFirstBuild: true
    },
  )}

the watch mode (npm run build:watch) starts immediately and triggers a build on the first run. This can cause issues in cases where:

  1. The serve command starts before the initial build is complete.
  2. The doc folder (or equivalent) does not exist prior to the build, leading to a 404 error when the serve command runs.

Currently, there is no built-in way to skip the initial run in watch mode and only trigger builds on subsequent file changes.

Use Case

Developers often need to ensure that the doc folder (or other build artifacts) is present before starting the server. For example:

  1. npm run build ensures that the doc folder exists.
  2. npm run build:watch watches for changes and rebuilds as needed.
  3. npm run serve serves the doc folder but should not start before the first build is complete.

Without the ability to skip the first build in watch mode, there is a race condition between the build and serve commands, causing issues for the user.

Proposed Solution

Introduce an option or flag (e.g., --skip-first-build) for the watch mode to skip the initial execution and only run on subsequent file changes.

Example:

  await esbuild.build({
    watch: true,
    skipFirstBuild: true
  )}

This would:

  1. Start watching files immediately.
  2. Only trigger a rebuild when changes are detected, skipping the initial run.

Workaround

Currently, developers must rely on custom scripts or tools to handle this, which adds unnecessary complexity. For example:

  • Writing scripts that conditionally skips the first build.

https://stackoverflow.com/questions/42495826/webpack-watch-with-skip-initial-build

Benefits

  • Simplifies the development workflow by avoiding race conditions.
  • Reduces the need for custom workarounds or scripts.
  • Provides a more intuitive experience for users running common dev setups.

Additional Context

This feature would be especially useful for projects where build artifacts are required before serving, such as:

  • Static site generators
  • Projects using bundlers or transpilers
  • Applications with a multi-step build process

Thank you for considering this feature request!

@hichemfantar hichemfantar changed the title Add Option to Skip First Run in Watch Mode Feature: Add Option to Skip First Run in Watch Mode Jan 23, 2025
@hichemfantar hichemfantar changed the title Feature: Add Option to Skip First Run in Watch Mode Feature: Add Option to Skip Initial Build in Watch Mode Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant