ice icon indicating copy to clipboard operation
ice copied to clipboard

[QUESTION]vite-plugin-index-html如何搭配injectHtml以及如何修改assetOutDir

Open xmsz opened this issue 3 years ago • 1 comments

背景

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
    <%- injectScript %>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="./src/main.ts"></script>
  </body>
</html>

  htmlPlugin({
        entry: './code/src/main.ts',
        template: './code/index.html',
      }),

      injectHtml({
        data: {
          injectScript: '<script src="https://cdn.staticfile.org/Swiper/7.4.1/swiper-bundle.min.js"></script>',
        },
      }),

但是实际上没有替换结果


生成的结果是

dist/index.html          
dist/main/main.9009b61d.css  
dist/main/main.27b39151.js   

这里的main如何自定义

xmsz avatar Jan 02 '22 15:01 xmsz

需求 1:通过 injectHtml 添加 script。看了这个插件的实现,无法支持。可以考虑在 vite-plugin-index-html 直接支持。 需求2:自定义 assetOutDir,通过 https://ice.work/docs/config/about/#outputassetspath 可以实现 需求3:hash 后缀可以通过 rollup 的 https://rollupjs.org/guide/en/#outputentryfilenames 来实现,问题可能在于需要插入到 html 中

这周我们考虑这么实现这三个需求

maoxiaoke avatar Jan 03 '22 10:01 maoxiaoke