I made a library that uses esbuild as the bundler and I need to set alias to some generated files (whose output path is based on user configuration), that would make it easier to access in the library itself:
// Instead of:
import { routes } from './some/path/to/.cache/generated-routes.js'
// I can do:
import { routes } from '@cache/generated-routes.js'
Frameworks can also use this option to define some built-in aliases like @
to current directory so users won't have to do that in tsconfig.json
or jsconfig.json
This sounds like a good use case for plugins. I believe the work-in-progress plugin API described in #111 should be able to address this need.
Hey @evanw, I hope you're doing well :) Can --define:K=V
be used to substitute react
with preact/compat
during parsing? (and therefore it can be used to substitute ./some/path/to/.cache
with @cache
too) I tried doing that but it didn't work. I guess it's only for boolean values then?
Closing this because you should be able to do this with the plugin API. The API is documented here: https://esbuild.github.io/plugins/.
Most helpful comment
This sounds like a good use case for plugins. I believe the work-in-progress plugin API described in #111 should be able to address this need.