-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 inject
in TransformOptions?
#984
Comments
This isn't allowed in the transform API because the inject feature requires a file system and the transform API is designed to not imply a file system. Ideally this would be possible with the build API and a plugin, but it looks like it's not currently possible without writing to the file system. I believe an action item here is to expose the paths of injected files to A meta comment: This feature request is part of a growing list of feature requests from people that basically want the transform API to work like the build API. I'm considering removing the transform API in the future and just having people use the build API instead. This should be reasonably ergonomic if a shortcut like #690 is implemented. |
Ahh right... Sorry, overlooked that important detail. I'll continue using the banner option to inject a content string. This works for my use case, and it'd work with the JSX example too, in a couple cases. I haven't put much thought into this of course, but I think keeping the transform API would be a nice shortcut, even if all it was a call to build w/ Happy for this to be closed btw. Thanks! |
Closing :) Doesn't seem like there are any actionables here & you already have related thought(s) logged. Thanks! |
The use case is the same as it is with
build
andbuildSync
, but at a per-file level. This is useful for register/loader hooks.For example, I'm currently doing something like
node -r ./bin/register.js test.ts
which uses esbuild to transform the contents oftest.ts
before executing it. This particular case needs some polyfills to be injected. Right now I'm (ab)usingbanner
to inject the polyfill, but that's probably not ideal :)This could also be used to auto-prepend something like
import { h } from 'preact';
at the top of every*.[tj]sx
file. This is listed here in the docs, but because it'sinject
-based, this feature is limited tobuild
s only.The text was updated successfully, but these errors were encountered: