-
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
how to change default interpret result in onLoad callbacks ? #1720
Comments
What you are trying to do is not well-defined. The same module can be imported in multiple places, and one import may look like Furthermore code may do I recommend having your plugin explicitly only remove the |
Thanks for your reply! but I don't know to do this with esbuild current api. The reasons are what I have said above:( sorry for my poor language )
|
There are various ways of doing this. One way would be to modify the imported file itself. For example, if the problem is that some code is doing let example = {
name: "example",
setup(build) {
build.onLoad({ filter: /[\/\\]a\.js$/ }, async (args) => {
let source = await fs.promises.readFile(args.path, "utf8");
// Change a CommonJS module into an ES module
source = `
var exports = {};
var module = { exports };
${source}
${Object.keys(require(args.path))
.map(x => `; export var ${x} = module.exports.${x}`)
.join('\n')}
`
return { contents: source };
});
},
}; You are basically rewriting the CommonJS module as an ES module, which then won't get a This is assuming you don't have control over the problematic code that is importing the library and then crashing. If you do, then the most straightforward solution is likely to just fix the code to not crash. Then you don't need to modify esbuild at all. |
Great work! |
Sorry, you'll have to figure out how to do that yourself. You can do this with an esbuild Keep in mind that what you're asking for is still not well defined because |
您发给我的信件已经收到,非常感谢!--------------------------------------------Yang shan 祝您愉快!
|
Thanks for this wonderful tool!!
When build a plugin,I've noticed that the callback added by onLoad can only get the path part of any import statements, but not the whole statement.
Also,what we can do is changing things before esbuild interpret it. if its possible to change interpret result ?
like:
if I write a plugin like this
I hope to get what esbuild original interpreted and change to something other .
Is any current apis allow me to do this ?
The text was updated successfully, but these errors were encountered: