samrum / vite-plugin-web-extension

A vite plugin for generating cross browser platform, ES module based web extensions.
MIT License
323 stars 33 forks source link

script replace is not work when using single quote #111

Closed WOSHIZHAZHA120 closed 1 year ago

WOSHIZHAZHA120 commented 1 year ago

I have a project where the prettier plugin will replace all double quotes with single quotes

The following code is working

<script type='module' src="./main.ts"></script>

The following is the formatted code, and the script replacement will be invalid at this time

<script type='module' src='./main.ts'></script>
samrum commented 1 year ago

Just to confirm, is this only an issue with HMR/dev mode?

WOSHIZHAZHA120 commented 1 year ago

Yes, the picture below is the result of building with single quotes src attribute 图片

The figure below is the dev mode, the src attribute has not changed 图片

If the src attribute is changed to double quotes, src will be replaced 图片

WOSHIZHAZHA120 commented 1 year ago

The problem might be here, I see you replaced "/ but didn't take into account the case of '/ https://github.com/samrum/vite-plugin-web-extension/blob/main/src/devBuilder/devBuilder.ts#L141

samrum commented 1 year ago

Right, yeah, should be simple to fix, thanks.

Also, just noting that I'm in the process of rewriting the way that HTML parsing logic works since it's not fully equivalent with the way Vite normally parses HTML

WOSHIZHAZHA120 commented 1 year ago

I try fixed it in #113, waiting for your review