Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

node.js - Can't change the base folder for lite-server in Angular 2 application

I am going through the 5 minute quickstart of Angular 2. However, my application resides in src/ folder instead of at the root of my repository, and when I run npm start the application is trying to find an index.html file at the root. I read up on lite-server and documentation shows that it uses BrowserSync and I can reconfigure BrowserSync with a bs-config.json in my repository. I did that and this is what my config looks like:

{
  "port": 8123,
  "server": { "baseDir": "./src" }
}

According to the log it's using the specified config:

[1] > [email protected] lite E:GitHubodo-app-angular2
[1] > lite-server "./bs-config.json"

I also tried an override through bs-config.js

module.exports = {
  port: 8123,
  server: {
    baseDir: "./src"
  }
};

However the Angular application is still opened on port 3000 and it's disregarding the baseDir defined in the config. What am I doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should use a file called bs-config.js (instead of a bs-config.json one) since lite-server tries to load a module using the require function. The configuration should be a valid Node module:

module.exports = {
  "port": 8123,
  "server": { "baseDir": "./src" }
};

See this line in the source code: https://github.com/johnpapa/lite-server/blob/master/lib/lite-server.js#L20.

This file by default is loaded from the user's project folder.

Edit

After digging a bit more, the first part of my answer relies on the code from github but not the one actually installed using npm install (version 1.3.4)

There are two options in this case:

  • port
  • baseDir

Using this command will fix your problem:

$ lite-server --baseDir ./src --port 3333

Hope it helps you, Thierry


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...