Abhay Pratap Rana
Abhay Pratap Rana

Reputation: 213

How to run vite server if index.html file is not in the root directory

enter image description here

How to fix this problem

I don't want to put index.html in directory tailwindcss.

Upvotes: 17

Views: 23903

Answers (3)

Maxim Paperno
Maxim Paperno

Reputation: 4869

Vite has a direct configuration option for this which can be specified in vite.config.js.

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

import { defineConfig } from 'vite';
import path from "path";

export default defineConfig({
  root: path.resolve('./src'),
  build: {
    // Relative to the root
    outDir: '../dist',
  },
});

Upvotes: 4

marktripney
marktripney

Reputation: 101

Vite looks for a root index.html by default. You can change this behaviour in package.json.

To do this, simply modify the following to suit...

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

In this example, I've put my entry index.html file inside a src folder. I tell Vite about this via serve, following that with the relevant directory (file path is relative to project root).

Read more here.

Upvotes: 6

Myk Willis
Myk Willis

Reputation: 12879

You could try specifying the entry point used by Rollup explicitly:

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

but honestly it feels like you're fighting against the tools, and you should have that package.json one directory up in your project.

Upvotes: 4

Related Questions