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
A request to allow plugins to set module metadata (e.g. type: 'module'
)
#2958
Comments
I agree that it'd be nice if you could do this with a plugin, but this is not the right approach. The I'm changing this issue from a request for a very specific API to a request for the ability to do this (however it ends up being implemented). |
type: 'module'
)
As the issue is changed to a general API to handle module identifier, I want to show the other problems I use onResolve, onLoad callback.
import Bg from '@images/bg.png';
import Video from '@videos/video.mp4';
import Bg from '@images/bg.png'
import Video4 from '@videos/video4.mp4';
export { Bg, Video4 } Currently, we can only set the same publicPath / assetName for assets. If developer use onResolve to customize their module resolution, the same module will have high possibility to load more times // Redirect all paths starting with "images/" to "./public/images/"
build.onResolve({ filter: /^@\// }, args => {
return { path: customResolve(args) }
})```
build.onLoad({ filter: /\.png$/ }, async (args) => {
let text = await fs.promises.readFile(args.path, 'utf8')
return {
contents: getPublicPath() + './images/' + Math.random() + text.split(/\s+/),
loader: 'txt',
}
})
build.onLoad({ filter: /\.mp4$/ }, async (args) => {
let text = await fs.promises.readFile(args.path, 'utf8')
await fs.writeFile(getOutputDir() +'/videos/' + text.split(/\s+/);
return {
contents: getPublicPath() + '/videos/' + text.split(/\s+/),
loader: 'txt',
}
}) The resolve result is the same, but the Math.random() in the onLoad callback will produce different loadResult for the two
If we use the same build.js from above, and the export |
I just came across this issue and would definitely love some API to either override the module metadata/type, or otherwise override the default export semantics heuristics. We have a large monorepo, with a single One approach I thought about was using an In any event, would love to see that or some other API in that direction. Thanks for all the work you do on esbuild! |
Reproduce Demo
test.js
build.js
with plugin
dist/test.js
without plugin
dist/test.js
The text was updated successfully, but these errors were encountered: