vite-plugin-html icon indicating copy to clipboard operation
vite-plugin-html copied to clipboard

本地开发多页面配置,生成的 index.html 和 other.html 都是基于 index.html 模板,other.html 模板没生效

Open panfei15623 opened this issue 2 years ago • 6 comments

本地开发多页面配置,生成的 index.html 和 other.html 都是基于 index.html 模板,other.html 模板没生效,想问一下如何能让 other.html 模板生效?

如下代码:

import { defineConfig } from 'vite'
import { createHtmlPlugin } from 'vite-plugin-html'

export default defineConfig({
  plugins: [
    createHtmlPlugin({
      minify: true,
      pages: [
        {
          entry: 'src/main.ts',
          filename: 'index.html',
          template: 'public/index.html',
          injectOptions: {
            data: {
              title: 'index',
            },
          },
        },
        {
          entry: 'src/other-main.ts',
          filename: 'other.html',
          template: 'public/other.html',
          injectOptions: {
            data: {
              title: 'other page',
            },
          },
        },
      ],
    }),
  ],
})

panfei15623 avatar Nov 03 '22 02:11 panfei15623

me too

JinZhang-96 avatar Nov 17 '22 10:11 JinZhang-96

me too

xiaoxiaobaibai avatar Nov 21 '22 15:11 xiaoxiaobaibai

要访问全路径

morance avatar Dec 08 '22 10:12 morance

要访问全路径

还是要看源码啊。那确切的说应该是template要和filename一致,并指向文件真实路径

JinZhang-96 avatar Dec 12 '22 07:12 JinZhang-96

同问,我也想这样操作,但没能成功

Whyjsee avatar Aug 16 '23 12:08 Whyjsee

最近也在搞这个问题,这样就不优雅了。配置需要template要和filename一致,并指向文件真实路径。关键是不放在root下面,带文件夹的话,比如 /src/entry, 那么访问路径也得加这个,那么配置的意义又在哪里

vincent-li avatar Dec 28 '23 05:12 vincent-li