【问题标题】:Vite.js not emitting HTML files in multi page appVite.js 不在多页应用程序中发出 HTML 文件
【发布时间】:2021-10-18 00:49:59
【问题描述】:

我有一个多页面应用程序,我正在尝试使用 Vite.js 构建(从 Webpack 迁移)。在构建 Vite + React 示例代码时,我看到它发出:

  • dist/index.html
  • dist/assets/<various assets>

但是,当我尝试制作一个如图所示的多页应用程序 in the docs 时,没有任何 HTML 被发出(但 /assets/ 的其余内容都在那里)。这是为什么呢?

// vite.config.js excerpt:
import { defineConfig } from 'vite'
import { dirname } from 'path';
import { fileURLToPath } from 'url';

export default defineConfig({
  root: 'client',
  build: {
    outDir: 'dist',
    rollupOptions: {
      input: {
        main: dirname(fileURLToPath(import.meta.url + 'index.html')),
        login: dirname(fileURLToPath(import.meta.url + 'login.html')),
      }
    }
  },
});

【问题讨论】:

  • remove dirname 删除文件名,只有目录名会被忽略。
  • @Chandan 如果我删除目录名,我会在vite build 期间收到错误消息,上面写着SyntaxError: Assigning to rvalue
  • 尝试new URL(./index.html, import.meta.url),如vite doc中指定的那样。
  • 你的建议奏效了@Chandan!把它放在一个答案中,我会接受它。 main: new URL('./client/index.html', import.meta.url).pathname,
  • 我已经发布了答案。

标签: javascript reactjs vite


【解决方案1】:

尝试将URL 用于vite doc 中指定的文件输入

main: new URL('./client/index.html', import.meta.url).pathname

【讨论】:

    猜你喜欢
    • 2022-01-22
    • 1970-01-01
    • 2013-12-01
    • 1970-01-01
    • 2022-10-18
    • 2023-03-29
    • 2016-11-06
    • 2011-12-03
    • 2021-01-15
    相关资源
    最近更新 更多