-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Allow file loader to resolve paths for files that do not exist at run time #8934
Comments
So I was right, a custom loader did the job:
However, this is not configurable using import attributes like I want (would need #7239). I'll have to settle for adding "query parameters" to the end of the import specifier. |
I wanted something similar; I wanted to be able to import any file (like a javascript file) but as plain text. I was able to support this via a custom non-existent file extension. To bypass the requirement that buns resolver finds a real file I have to create an empty file in the onResolve function and then immediately spawn an async unlink to clean the file up after the synchronous onResolve function returns:
|
What is the problem this feature would solve?
My goal is to use an import to resolve a file path for an asset that does not exist, generate an asset file at that file path, and include that generated asset file in the build. I cannot achieve this, because the file loader throws an error when the file is missing, and there is no mechanism to configure the file loader to simply resolve the path.
What is the feature you are proposing to solve the problem?
I am proposing the file loader should not validate that the file exists at run time (but should still validate at build time).
Alternatively, a richer feature would be a follow-up to #5519 to allow configuration of loaders using import attributes. Something like
import imageUrl from "./assets/background.png" with { loader: "file", validateExists: 'build' }
.This would tell Bun to use the "file" loader, and to only validate if the file exists at build time. By default,
validateExists
would be"always"
, which would throw an error during run time (current behavior).What alternatives have you considered?
There is no alternative for this. I am considering implementing my own file loader plugin.
The text was updated successfully, but these errors were encountered: