我正在尝试使用angular 5客户端构建快速服务器。我在一个“dev”脚本中一起使用“ts-node”和“nodemon”和“ng build --watch”,因此它们可以自动编译在一起。应用程序每次更改时,nodemon都会说应用程序崩溃了。如果我删除行app.listen,它将每次都有效,没有任何错误。
package.json脚本:
"dev": "concurrently --kill-others \"nodemon --config ./servernodemon.json\" \"ng build --watch\"",
servernodemon.json:
{
"delay": "500",
"ignore": ["servernm/**/*.spec.ts"],
"verbose": true,
"exec": "ts-node server/server.app.ts",
"watch": ["server"],
"ext": "ts"
}
server.app.ts:
import 'reflect-metadata';
import * as express from 'express';
const path = require('path');
console.log('Revving up server');
const app: express.Express = express();
app.use(express.static(path.join(__dirname, '../dist-site')));
app.get('/*', (req: express.Request, res: express.Response) => {
res.sendFile(path.join(__dirname, '../dist-site/index.html'));
});
console.log('Starting server');
const port = process.env.PORT || 3005;
app.listen(port, () => {
console.log(`Server listening on port ${port}!`)
}).on('error', (err) => {
console.error('Failed to start server', err);
});
3次更改和初次运行后的控制台输出:
$ npm run dev
> project@0.0.0 dev /Users/project
> concurrently --kill-others "nodemon --config ./servernodemon.json" "ng build --watch"
[0] [nodemon] 1.13.2
[0] [nodemon] reading config /Users/project/servernodemon.json
[0] [nodemon] to restart at any time, enter `rs`
[0] [nodemon] or send SIGHUP to 40641 to restart
[0] [nodemon] ignoring: /Users/project/.git/**/* .nyc_output .sass-cache bower_components coverage /Users/project/node_modules/**/* server/**/*.spec.ts
[0] [nodemon] watching: /Users/project/server/**/*
[0] [nodemon] watching extensions: ts
[0] [nodemon] starting `ts-node server/server.app.ts`
[0] [nodemon] child pid: 40644
[0] [nodemon] watching 2 files
[0] Revving up server
[0] Starting server
[0] Server listening on port 3005!
[0] [nodemon] files triggering change check: server/server.app.ts
[0] [nodemon] matched rule: **/Users/codybrooks/project/server/**/*
[0] [nodemon] changes after filters (before/after): 1/1
[0] [nodemon] delaying restart for 500ms
[0] [nodemon] restarting due to changes...
[0] [nodemon] server/server.app.ts
[0]
[0] [nodemon] app crashed - waiting for file changes before starting...
[1] Date: 2017-12-16T16:14:02.235Z
[1] Hash: b5d642e77abf8ebb4d1a
[1] Time: 6247ms
[1] chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
[1] chunk {main} main.bundle.js, main.bundle.js.map (main) 7.77 kB [initial] [rendered]
[1] chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 199 kB [initial] [rendered]
[1] chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 11.4 kB [initial] [rendered]
[1] chunk {vendor} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.33 MB [initial] [rendered]
[0] [nodemon] files triggering change check: server/server.app.ts
[0] [nodemon] matched rule: **/Users/project/server/**/*
[0] [nodemon] changes after filters (before/after): 1/1
[0] [nodemon] delaying restart for 500ms
[0] [nodemon] restarting due to changes...
[0] [nodemon] server/server.app.ts
[0]
[0] [nodemon] starting `ts-node server/server.app.ts`
[0] [nodemon] child pid: 40656
[0] Revving up server3
[0] Starting server
[0] Server listening on port 3005!
[0] [nodemon] files triggering change check: server/server.app.ts
[0] [nodemon] matched rule: **/Users/project/server/**/*
[0] [nodemon] changes after filters (before/after): 1/1
[0] [nodemon] delaying restart for 500ms
[0] [nodemon] restarting due to changes...
[0] [nodemon] server/server.app.ts
[0]
[0] [nodemon] app crashed - waiting for file changes before starting...
包的版本:
"concurrently": "^3.5.1",
"nodemon": "^1.13.2",
"tslint": "^5.7.0",