-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Vite removes external module from index.html #3533
Comments
Problem seems to be in: vite/packages/vite/src/node/plugins/html.ts Line 143 in 496e26e
I reckon we need a way of manually forcing externalUrl for certain relative urls. |
Hi @hatchette , you can put your 'my-lib.mjs' in 'public' dir. And reference the js file like this: <script type="module" src="/my-lib.mjs"></script> Here is the code: vite/packages/vite/src/node/plugins/asset.ts Lines 132 to 147 in 144b92c
|
Took a look at this one today. Seems to be tricky to fix. The place where we're removing the script tag is here. vite/packages/vite/src/node/plugins/html.ts Line 295 in a30a548
This line naively remove the script tag regardless if it resolves to something. The issue is that to determine if the file is externalized, we have to do something like Either we need |
@hatchette It seems to same with #7160, even no config |
no. expected output
|
Is there any updates on this issue? |
This feature would be much appreciated! |
One more case
But, if i add code with side-effect in script
script doesn't be delete |
These are also be removed from the
|
...so what's the workaround? nothing i try works, and I can't build my project whatsoever because of this. |
@jayleaf the workaround tag was added erroneously by @bluwy, there is no workaround. We are using unix sed to cut all public references out of the index.html before the build and then add them back afterward in our build pipeline. It's ridiculous but we tried raising a PR (#11854), we are gold sponsors of both Vue and Vite and offered to pay any amount to get this bug fixed. No one cares. |
@leonheess yeah that's pretty ridiculous. Thank you for linking the PR. This is definitely more than "nice to have" lol. |
The workaround for us is: Yea, pretty ugly.
|
Describe the bug
Vitejs will remove external module declared in index.html if module has relative path.
Reproduction
index.html
vite.config.js
Note that in production /external/my-lib.mjs is reverse-proxy to different deployment.
Changing url to https://host/... works, but this is not what we want, because we simply don't know the hostname at build time (it's deployed to more than single host).
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: npm
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: