vite-plugin-import-maps icon indicating copy to clipboard operation
vite-plugin-import-maps copied to clipboard

The plugin fails to work in Vite@3

Open dylanzbot opened this issue 1 year ago • 6 comments

Describe the bug

In the development environment of Vite@2, after the plugin is executed, <script type="importmap"> is at the top of the head tag, and /@vite/client is below it, this is no problem; but in the development environment of Vite@3, because Vite adjusted the injection rules of the plugin execution result(applyHtmlTransforms function), <script type="importmap"> was under /@vite/client, and the browser could not parse the import maps.

在Vite@2的开发环境中,插件执行完后在head标签中<script type="importmap">位于最顶部,/@vite/client在它下面,这个没有问题;但是在Vite@3的开发环境中,由于Vite调整了插件执行结果的注入规则(applyHtmlTransforms函数),导致<script type="importmap">/@vite/client下面,浏览器就无法解析 Import maps 了。

System Info

Vite 3.0.8

Personal solution

enforce: 'post', // or delete it

I tested it, it works.

dylanzbot avatar Aug 21 '22 18:08 dylanzbot