Description
Is your feature request related to a problem? Please describe.
Currently vite generates the entry point in the index.html as a <script type="module">
. Modules enforce CORS. CORS doesn't work for file:///
. Ref: MDN. So going in dist and double clicking on your index kinda leads to nowhere.
Describe the solution you'd like
I'm not entirely sure of all possible considerations, but...
Vite already supports the rollup output options. And rollup docs already give a hint:
output.format
iife
– A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this.)
So I was thinking, if output format is iife
(and possibly umd
), render <script defer>
instead of <script type="module">
Not sure how much hidden voodoo this counts as, but coupling format=es and type=module and format=iife and regular script seems reasonable to me. I guess it can be made more explicit with a separate config option.
Describe alternatives you've considered
Well I don't have any in this case, at least on the vite side. I considered doing things by hand, but perusing the code has been an illuminating experience. It looks readable and clear enough that I feel like I can make the proposed change myself. Though this will be my first foray into typescript.
Additional context