Skip to content
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

Support dynamic imports #198

Open
cowwoc opened this issue Oct 4, 2024 · 1 comment
Open

Support dynamic imports #198

cowwoc opened this issue Oct 4, 2024 · 1 comment

Comments

@cowwoc
Copy link
Contributor

cowwoc commented Oct 4, 2024

I suspect this plugin might have a problem with dynamic imports. Given ThemeChooser.mts that contains:

const htmlAsString = await import("./ThemeChooser.html", {with: {type: "html"}}) as { default: string };

I get this esbuild output:

  target\classes\theme\ThemeChooser-QGTYAYZG.js    248.7kb
  target\classes\chunk-YEX2IMXM.js                   1.6kb
  target\classes\theme\ThemeChooser-R7JEJFRF.html    1.3kb
  target\classes\theme\ThemeChooser-YVQTYOLV.js      168b 

Looking on disk, ThemeChooser-QGTYAYZG.js is created and references ThemeChooser-YVQTYOLV.js but the latter file does not exist.

Do you have any idea why the file isn't being created? Maybe try adding a unit test for handling dynamic imports?

@cowwoc
Copy link
Contributor Author

cowwoc commented Oct 4, 2024

Debugging this further, I am seeing the following:

The dynamic import is transformed into const htmlAsString = await import("./ThemeChooser-YVQTYOLV.js"); inside ThemeChooser-QGTYAYZG.js.

Notice that the original import was for an HTML file but the bundled version is now referring to a JS file. Next, the html file is actually being bundled... but it's called ThemeChooser-R7JEJFRF.html. So it looks like the generated import statement is simply referring to the wrong filename.

I'm not sure how to debug this further without your help...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant