vite如何配置 script 去除  type="module" crossorigin ?

我是用vite构建了一个vue3的应用,这个项目会本地离线访问即双击index.html的形式访问,但因为构建后的script标签保护那两个属性,会导致报错,我该怎么修改我的vite.config.js

阅读 7k
1 个回答

在vite配置里自定义plugin替换一下:

const noAttr = () => {
  return {
    name: "no-attribute",
    transformIndexHtml(html) {
      return html.replace(`type="module" crossorigin`, "");
    }
}

export default defineConfig({
  plugins: [noAttr()]
})
推荐问题