问题描述
使用 angular-cli,我创建了一个新的入门应用程序.ng new my-app
.然后我做了 ng serve
并且它在 localhost:4200
上运行良好.接下来,我使用 ng build
并使用创建的应用程序创建了一个 dist
文件夹.
Using angular-cli, i created a new starter app. ng new my-app
. Then i did ng serve
and it worked fine on localhost:4200
. Next, i used ng build
and it created a dist
folder with the created app.
我使用的是最新的 angular-cli,它使用 webpack.
I'm using the latest angular-cli and it uses webpack.
现在,我想使用 node 在本地环境中使用该应用程序(如果可能.如果不是,那么我想在 WAMP 上我将编写一个 php 后端 api).我在 Windows 10 机器上,64 位.
Now, i want to use the app in a local environment using node (If that's possible. If it's not, then i guess on WAMP in which i will write a php backend api). I am on a windows 10 machine right, 64 bit.
下一步是什么?我是 nodejs 托管设置的新手.
What are the next steps? I am new to nodejs hosting setup.
最终,我想为我的办公室创建一个小应用程序来处理行政工作.大约 12-15 人将使用它,所有这些人都连接在本地网络中.
Eventually, i want to create a small app for my office to handle administrative work. It will be used by about 12-15 people all connected in a local network.
我是 nodejs 托管设置的新手.
I am new to nodejs hosting setup.
推荐答案
您可以将 express 与 node.js 一起使用,并将您的 dist 内容作为静态内容提供这样的内容(没有测试但应该可以工作,我做了一些事情在另一个项目中类似):
you can use express with node.js and serve your dist content as static content with something like this (didn't test it but should work, I did something similar in another project):
var express = require('express');
var app = express();
app.use(express.static('dist'));
var server = app.listen(8080, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
如果您只想出于开发目的而这样做,在我看来,您可以使用服务器设计的临时设置不同的流程,以便在更改代码时重新编译\重新加载应用程序,而无需每次都构建并运行 node.js服务器(开发流程很慢).我个人使用 webpack-dev-server 和 webpack.
if you want to do it just for development purpose, in my opinion you can setup a different flow using server designed ad hoc to recompile\reload the application when you change the code, without building every time and run the node.js server (much slow development flow). I personally use webpack-dev-server with webpack.
这篇关于Angular 2 应用程序 - 如何在节点上的本地环境中部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!