如果index.html文件不在根目录下,如何运行vite服务器

Abh*_*ana 14 web-deployment node.js npm tailwind-css vite

在此输入图像描述

  • Index.html 和 app.css 位于 /tailwindcss/... 之外
  • Vite 服务器正在运行,但无法在本地主机上运行。

如何解决这个问题

我不想将index.html 放在目录tailwindcss 中。

小智 5

index.htmlVite默认寻找root 。您可以在 中更改此行为package.json

为此,只需修改以下内容以适应...

"scripts": {
  "dev": "vite serve ./src"
},
Run Code Online (Sandbox Code Playgroud)

在此示例中,我将条目index.html文件放入一个src文件夹中。我通过 告诉 Vite 此事serve,然后是相关目录(文件路径相对于项目根目录)。

在这里阅读更多内容。


Myk*_*lis 4

您可以尝试显式指定 Rollup 使用的入口点:

// vite.config.ts
export default {
  build: {
    rollupOptions: {
      input: {
        // entry point for compilation; normally would be "./index.html"
        app: '../index.html',
Run Code Online (Sandbox Code Playgroud)

但说实话,感觉就像你在与工具作斗争,你应该package.json在你的项目中建立这个目录。