Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Can';t在Angular 2应用程序中更改lite服务器的基本文件夹_Node.js_Angular_Browser Sync_Lite Server - Fatal编程技术网

Node.js Can';t在Angular 2应用程序中更改lite服务器的基本文件夹

Node.js Can';t在Angular 2应用程序中更改lite服务器的基本文件夹,node.js,angular,browser-sync,lite-server,Node.js,Angular,Browser Sync,Lite Server,我正在通过考试。但是,我的应用程序驻留在src/文件夹中,而不是存储库的根目录下,当我运行npm start时,应用程序正在尝试在根目录下查找index.html文件。我阅读了lite server,文档显示它使用BrowserSync,我可以在我的存储库中使用bs config.json重新配置BrowserSync。我这样做了,我的配置是这样的: { "port": 8123, "server": { "baseDir": "./src" } } 根据日志,它正在使用指定的配置:

我正在通过考试。但是,我的应用程序驻留在
src/
文件夹中,而不是存储库的根目录下,当我运行
npm start
时,应用程序正在尝试在根目录下查找
index.html
文件。我阅读了
lite server
,文档显示它使用
BrowserSync
,我可以在我的存储库中使用
bs config.json
重新配置
BrowserSync
。我这样做了,我的配置是这样的:

{
  "port": 8123,
  "server": { "baseDir": "./src" }
}
根据日志,它正在使用指定的配置:

[1] > todo-app-angular2@1.0.0 lite E:\GitHub\todo-app-angular2
[1] > lite-server "./bs-config.json"
我还尝试了通过bs-config.js进行覆盖

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

但是Angular应用程序仍然在端口3000上打开,它忽略了配置中定义的baseDir。我做错了什么?

您应该使用名为
bs config.js
(而不是
bs config.json
one)的文件,因为lite server尝试使用
require
函数加载模块。配置应为有效的节点模块:

module.exports = {
  "port": 8123,
  "server": { "baseDir": "./src" }
};
请参阅源代码中的这一行:

默认情况下,此文件从用户的项目文件夹加载

编辑

在进一步挖掘之后,我的答案的第一部分依赖于github的代码,而不是使用
npm install
(版本1.3.4)实际安装的代码

在这种情况下,有两种选择:

  • 端口
  • baseDir
使用此命令将修复您的问题:

$ lite-server --baseDir ./src --port 3333
希望它能帮助你,
Thierry

Thierry Templier给出的答案不再正确,您可以使用
bs config.json
bs config.js
配置来调整浏览器同步配置。这就是我最初提出的JIT(即时)和AOT(提前)编译支持(
bs config.json

从多个目录托管项目

但是,我不喜欢这个解决方案,因为通过覆盖
json
文件中的
server
部分,默认的
middleware
配置同时被覆盖

因此,我以以下方法结束,我使用默认的
config defaults.js
文件并对其进行了修改():


尝试在
npm start
命令中添加
--config path/to/bs config.json
。请确保在浏览器同步配置选项文件中使用lite server v2。我实际上忘记提到我已经尝试过了。我将json配置替换为bs-config.js文件中的module.export。这仍然没有起到任何作用:(实际上,当我添加此项时,我的npm启动将失败。我刚刚尝试了它,它仍然从提供服务。/[1][BS]访问URL:[1]------------------------------------[1]本地:[1]外部:[1]------------------------------------[1]UI:[1]外部:[1]------------------------------------[1][BS]从以下位置提供文件:./您使用哪个版本的lite server?@ShawnNorthrop是的,您可以利用
--files
参数。指定此级别的文件模式。类似于
/***.js
…请确保将lite server v2用于浏览器同步配置选项文件
{
  "port": 8000,
  "server": ["app", "."]
}
'use strict';
var fallback = require('connect-history-api-fallback');
var log = require('connect-logger');
/*
 | For up-to-date information about the options:
 |   http://www.browsersync.io/docs/options/
 */
module.exports = {
  port: 8000,
  injectChanges: false, // workaround for Angular 2 styleUrls loading
  filters: ['./**/*.{html,htm,css,js}'],
  watchOptions: {
    ignored: 'node_modules'
  },
  server: ['./', 'app'],
  middleware: [
    log({ format: '%date %status %method %url' }),
    fallback({
        index: '/index.html',
        htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'] // systemjs workaround
    })
  ]
};