lite-server icon indicating copy to clipboard operation
lite-server copied to clipboard

Configure lite-server to open an index.html from a subfolder

Open RayBowman2017b opened this issue 6 years ago • 2 comments

Before you open an issue, please check if a similar issue already exists or has been closed before.

A descriptive title

The behavior you expect to see, and the actual behavior...

For feature requests, a description of the problem you're trying to solve, including why you think this is a problem.

I am trying to configure live-server to use the index.html and code from a subfolder off of the root folder


bs-config.json

{ "port": 3000, "files" : [ "./SEC010/*.{js, html}" ], "open" : "/SEC010/index.html", "server": { "baseDir": "./" }, "http" : true, "browser": ["chrome"] }

If I set baseDir to ./SEV010, it will load the index.html from that sub-folder, but then how do I get live-server to utilize the node_modules sub-folder in the root folder?

Bug repro steps

Please give us an isolated way to reproduce the behavior (example: GitHub repository with code that anyone can clone to observe the problem, or a Dockerfile that replicates your environment):

Environment

  • lite-server version:
  • nodejs version:
  • npm version:
  • OS type/version:

RayBowman2017b avatar Mar 15 '19 16:03 RayBowman2017b

Hello, I have the same issue. All work ok in root directory of my project. www.myweb.com But when I click in a link to subfolder, then it does not pull the index.html www.myweb.com/contact/ I works when you change the link to www.myweb.com/contact/index.html

The problem is I dont want to use a complete link www.myweb.com/contact/index.html but only www.myweb.com/contact/

How can I configure bs-config.json to do this ?

JulioCoder avatar Sep 12 '20 01:09 JulioCoder

I've explained how to do this here: https://minaelee.medium.com/setting-basedir-in-lite-server-bs-config-and-still-access-node-modules-673bf523d09d

Long story short, add this to your bs-config.json:

{
    "server": { 
        "baseDir": "./src",
        "routes": { "/node_modules": "node_modules" }
    }
}

Or this to your bs-config.js (one or the other):

module.exports = {
    server: {
        baseDir: './src',
        routes: {
            '/node_modules': 'node_modules'
        }
    }
}

Update ./src to whatever folder you are using as your baseDir. Make sure you call lite-server using the -c bs-config.json flag. Good luck!

minaelee avatar Nov 25 '20 03:11 minaelee