-
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
[Question] Dynamic imports #661
Comments
Are you asking for something like a As a router I imagine you want the import to not be bundled. |
Check out #641 @heyheyhello. |
Hey @heyheyhello. I don’t have experience with I’ll try to provide some more context: For the router I’m working on, I would like the router to be invisible to the end-user. This would be different from routers like React Router and more similar to routers like Gatsby and Next. The user creates pages @ggoodman Is what you’re talking about similar to what I’m trying to achieve but is internal only right now? |
Got it. Thank you! I’ll try my naive solution for now (writing a file to disk and running esbuild on that) and hopefully in the future I can skip this step and use esbuild without an intermediary step. I’ll leave this open to give Evan a chance to see this. Otherwise, I think this can be closed in general. |
Closing per the conversation above. Glad you were able to find a workaround. |
Nevermind, still figuring this out. |
I’m experimenting with using esbuild for a page-based router for React (work here: https://github.com/zaydek/page-based-router) and I just ran into the warning about dynamic imports using esbuild:
warning: This dynamic import will not be bundled because the argument is not a string literal (surround with a try/catch to silence this warning)
warning: This call to "require" will not be bundled because the argument is not a string literal (surround with a try/catch to silence this warning)
I did search and found these: https://github.com/evanw/esbuild/issues?q=This+call+to+%22require%22+will+not+be+bundled+because+the+argument+is+not+a+string+literal but I didn’t get an answer I was looking for.
When building something that requires dynamic imports, would it be recommended that instead I build a JS / TS file to disk that uses static imports and then use esbuild on that file?
Step 1: Build the following file from dynamic paths
["A", "B"]
:Step 2: Run esbuild on this generated file.
Or this there another way to resolve dynamic imports using esbuild? I understand the intention to not resolve dynamic imports but I also don’t know what to do instead, other than the previous two steps.
Could dynamic imports be resolved using a custom plugin?
The text was updated successfully, but these errors were encountered: