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

Watch mode and entryNames including a hash #1186

Closed
rosenfeld opened this issue Apr 23, 2021 · 9 comments
Closed

Watch mode and entryNames including a hash #1186

rosenfeld opened this issue Apr 23, 2021 · 9 comments

Comments

@rosenfeld
Copy link

Even for the development mode I use a hash in the entry points to enable proper caching, which is especially important when working on loading performance improvements.

When the watch mode is on, esbuild will keep creating new files upon each change without removing the old generated files. Shouldn't the watch mode take care of automatically removing files generated by previous builds?

Also, I miss a plugin that would generate some sort of manifest JSON file mapping the generated entry point bundle for each entry point. Our server application runs Ruby, not JavaScript, so the application must know how to find the right bundle for each supported entry point. Are there built-in plugins that would take care of removing old files generated by previous builds and generating some manifest JSON file for use with a generic web server?

@evanw
Copy link
Owner

evanw commented Apr 26, 2021

The latest release includes onStart and onEnd callbacks, which should now make it possible to implement a plugin that does both of these things. See the release notes for details: https://github.com/evanw/esbuild/releases/tag/v0.11.15. If you set build.initialOptions.metafile = true in your plugin's setup function, the build result returned in onEnd will have a JSON manifest in the metafile property with lots of information including enough information to associate output files with input entry points.

@rosenfeld
Copy link
Author

Hi @evanw, thanks! I'm trying to get it working, however I can't get onEnd called upon each build when enabling the watch mode:

// build.js
require('esbuild').build({
  entryPoints: ['app.js'],
  outdir: 'out',
  watch: true,
  incremental: true,
  plugins: [
    {
      name: 'test',
      setup(build) {
        build.initialOptions.metafile = true;
        build.onEnd(result => {
          console.log('onEnd', result.metafile);
        });
      },
    },
  ],
});


// -------------
// app.js

console.log('test');

The onEnd callback is only getting called once, just after the initial build. The watch mode seems to be working because out/app.js changes if I change app.js.

What am I missing?

@rosenfeld
Copy link
Author

I've used the watch callback function to generate the manifest and clean-up old files until this is fixed in the plugins API.

@evanw
Copy link
Owner

evanw commented Apr 28, 2021

It looks like onEnd currently only fires with watch mode when you also have an onRebuild callback too. I'll fix that in the next release but in the meantime I think you can add an empty onRebuild callback to work around this bug:

watch: { onRebuild() {} },

@evanw
Copy link
Owner

evanw commented Apr 28, 2021

The fix should now be published in version 0.11.16.

@rosenfeld
Copy link
Author

I've just tried the new release and the problem is not that onEnd is not being called, but that it only gets the metafile in the first call but not for the subsequent calls. I'm relying on onRebuild for now to get access to the metafile, but ideally this should be fixed so that onEnd also gets the metafile for subsequent runs with the watch mode enabled.

@evanw
Copy link
Owner

evanw commented May 1, 2021

This issue should be fixed in the latest release by the way. Thanks for the report.

@rosenfeld
Copy link
Author

Awesome, thanks!

@geoffharcourt
Copy link

Thank you for this, getting access to the metafile in rebuilds was a game-changer for us and made using esbuild's watch mode possible for our team in development.

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

3 participants