根目录下没有index.html文件如何运行vite服务器

问题描述 投票:0回答:3

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

如何解决这个问题

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

node.js npm web-deployment tailwind-css vite
3个回答
5
投票

Vite 默认查找根

index.html
。您可以在
package.json
中更改此行为。

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

"scripts": {
  "dev": "vite serve ./src"
},

在此示例中,我将条目

index.html
文件放入
src
文件夹中。我通过
serve
告诉Vite这一点,然后是相关目录(文件路径相对于项目根目录)。

阅读更多这里


4
投票

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

// vite.config.ts
export default {
  build: {
    rollupOptions: {
      input: {
        // entry point for compilation; normally would be "./index.html"
        app: '../index.html',

但说实话,感觉就像你在与工具作斗争,你应该在你的项目中拥有

package.json
一个目录。


0
投票

Vite 有一个直接配置选项,可以在 vite.config.js 中指定。

https://vitejs.dev/config/shared-options.html#root

export default defineConfig({
  root: 'src',
  build: {
    // Relative to the root
    outDir: '../dist',
  },
});
© www.soinside.com 2019 - 2024. All rights reserved.