-
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 to set module alias via Node.js API #266
Comments
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 |
Closing this because you should be able to do this with the plugin API. The API is documented here: https://esbuild.github.io/plugins/. |
Hello! This Issue comes up when Googling for making preact compat work, I wrote a little plugin if anyone wants an idea of how to make this work: const preactCompatPlugin = {
name: "preact-compat",
setup(build) {
const path = require("path");
const preact = path.join(process.cwd(), "node_modules", "preact", "compat", "dist", "compat.module.js");
build.onResolve({filter: /^(react-dom|react)$/}, args => {
return {path: preact};
});
}
} If there was a way to just replace the dependency name I couldn't find one, but these seems to work fine for now. |
I wonder if you can use NPM alias technique like below with esbuild: https://github.com/developit/nextjs-preact-demo/blob/master/package.json#L18 cc: @PaulBGD |
Thank you for your help @PaulBGD and you are right that is exactly how I ended up finding your solution 😄 |
Thanks for your help everyone :) @osdevisnot that was exactly what I needed. |
Use Case
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:
Frameworks can also use this option to define some built-in aliases like
@
to current directory so users won't have to do that intsconfig.json
orjsconfig.json
The text was updated successfully, but these errors were encountered: