1.安装 npm i browser-sync
2. 再angular.json里配置
"serve-ssr": {"builder": "@nguniversal/builders:ssr-dev-server","options": {"ssl": true,"sslCert": "./node_modules/browser-sync/certs/server.crt","sslKey": "./node_modules/browser-sync/certs/server.key"},
3.server.ts 修改function run()
function run(): void {const port = process.env['PORT'] || 4200;// https certificatesconst privateKey = fs.readFileSync('./node_modules/browser-sync/certs/server.key');const certificate = fs.readFileSync('./node_modules/browser-sync/certs/server.crt');// Start up the Node server
// Start up the Node server
let server;
if (process.argv && process.argv.includes('--ssl')) {server = https.createServer({ key: privateKey, cert: certificate }, app());
} else {server = app();
}server.listen(port, () => {console.log(`Node Express server listening on https://localhost:${port}`);});
}