-
Notifications
You must be signed in to change notification settings - Fork 93
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
Support generating build meta #235
Comments
--metafile
flag to support with esbuild
I love the idea! Renamed PR title to introduce it as an option (we could enable also via CLI flag). |
Cool. I checked out the source to see if I'm able to implement the feature. I understand that It seems that export let build: typeof types.build = (options: types.BuildOptions) {} // ... https://esbuild.github.io/api/#build
https://esbuild.github.io/api/#transform When selecting plugins: [
{
buildEnd() {
const deps = [];
for (const id of this.getModuleIds()) {
const m = this.getModuleInfo(id);
if (m != null && !m.isExternal) {
for (const target of m.importedIds) {
deps.push({ source: m.id, target })
}
}
}
fs.writeFileSync(
path.join(__dirname, 'graph.json'),
JSON.stringify(deps, null, 2));
},
}
] But it additionally requires a output: {
file: '`${outFolder}/dist.js',
format: 'iife',
name: 'PROJECT_NAME',
sourcemap: true,
} Since I just saw the issue #236, it would be possible to add a import { writeFile } from "node:fs/promises";
import type { Plugin } from "rollup";
import { resolve } from "pathe";
export interface MetafileOptions {
enable?: boolean;
}
export interface MetaInfo {
source: string;
target: string;
}
const defaults: MetafileOptions = {
enable: false,
};
export function metafilePlugin(opts: MetafileOptions = {}): Plugin {
opts = { ...opts, ...defaults };
return {
name: "unbuild-metafile",
async buildEnd(err) {
if (!err && opts.enable) {
const deps: MetaInfo[] = [];
for (const id of this.getModuleIds()) {
const m = this.getModuleInfo(id);
if (m != null && !m.isExternal) {
for (const target of m.importedIds) {
deps.push({ source: m.id, target });
}
}
}
if (Array.isArray(deps) && deps.length === 0) {
return;
}
const outPath = resolve(__dirname || process.cwd(), "graph.json");
await writeFile(outPath, JSON.stringify(deps), "utf8");
}
},
} as Plugin;
} @pi0 what you think? |
Hi @jrson83 . Sorry for checking late on this. sourcemap support is now added for rollup. Plugin implementation seems nice. Do you still like to work on this feature? |
Great, sure I will see what I can do and let you know 😀 |
Describe the feature
tsup
already integrated the--metafile
flag to tell esbuild to produce some metadata about the build in JSON format.It is great for analyzing with bundle-buddy.com. To see support for this in unbuild would be great!
More Info:
Additional information
The text was updated successfully, but these errors were encountered: