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

How to create a "metafile"? #121

Closed
taschmidt opened this issue Apr 25, 2021 · 6 comments · Fixed by #129
Closed

How to create a "metafile"? #121

taschmidt opened this issue Apr 25, 2021 · 6 comments · Fixed by #129
Labels

Comments

@taschmidt
Copy link
Contributor

I tried adding metafile: meta.json but got an error from esbuild that metafile must be a boolean. So I changed it to metafile: true. The build ran successfully but I was never able to find any output. Has anyone managed to analyze their esbuild bundle sizes?

@floydspace
Copy link
Owner

hi @taschmidt, I checked the issue. As long as we are using esbuild's JavaScript API (not CLI), metafile option behaves a bit different, instead of defining a metafile name it receives a boolean value (according to esbuild source code, unfortunately it's not documented), and if the value is true the metadata is returned in the build result as JS object, so you can find your meta in the result variable here:

const result = await build(config);

@taschmidt
Copy link
Contributor Author

Yeah sorry, I did do some digging in esbuild and saw that it appears you can only do it via code. It might be handy to check here if metafile is true and, if so, dump it out to meta.json or something.

@github-actions
Copy link

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@floydspace
Copy link
Owner

Hey @taschmidt , if it's still relevant for you, I completed the fix that will save metafile alongside the main bundle.

@taschmidt
Copy link
Contributor Author

Awesome! Thanks so much!

@linonetwo
Copy link

Thanks, get it.

so we can have the solution:

const result = await esbuild.build({
  write: false,
  // we will have result.metafile later
  metafile: true,
  // other configs...
  entryPoints: packageJSON.tsFiles.map((tsFileName) => `./src/${tsFileName}.ts`),
  bundle: true,
  minify: false,
  sourcemap: process.env.CI ? false : 'inline',
  //....
});

// output bundle
for (let out of result.outputFiles) {
  await fs.mkdirp(path.dirname(out.path));
  await fs.writeFile(
    out.path,
    new TextDecoder()
      .decode(out.contents),
    'utf8',
  );
}

if (result.metafile) {
  // use https://bundle-buddy.com/esbuild to analyses
  await fs.writeFile('./dist/metafile.json', JSON.stringify(result.metafile));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants