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

On-resolve result suffix property also requires path property? #3790

Closed
IanBellomy opened this issue May 30, 2024 · 1 comment
Closed

On-resolve result suffix property also requires path property? #3790

IanBellomy opened this issue May 30, 2024 · 1 comment

Comments

@IanBellomy
Copy link

In the mock plugin below, I expected onLoad's args.suffix to match what was returned from onResolve, but it's only there if path is also included in the onResolve results.

I have no experience with bundler plugins though and so assume this is working as expected and that I'm just missing some common knowledge, but it may be nice if the docs noted the path requirement. ✌️

import * as path from "path";
export const test = (options = {}) => ({
	name: "test",
	setup(build) {
		build.onResolve({ filter: /\.svg$/ }, async (args) => {
			if (!args.suffix) {
				return {
					suffix: "?my-suffix"
					// path: path.join(args.resolveDir, args.path), // suffix is only set if path included
				};
			}
		});
		
		build.onLoad({ filter: /\.svg$/ }, async (args) => {
			console.log("test suffix", args.suffix); // suffix is "" unless path is included in onResolve
		});
	},
});
@evanw
Copy link
Owner

evanw commented Jun 30, 2024

This is because esbuild only uses the value returned by onResolve if it successfully resolves the path (either by returning a path or setting external: true. I can generate a warning when this happens.

@evanw evanw closed this as completed in 94f09ea Jun 30, 2024
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

2 participants