Angular 2应用程序-如何在节点上的本地环境中部署? [英] Angular 2 app - How to deploy in a local environment on node?
问题描述
使用angular-cli,我创建了一个新的入门应用程序. ng new my-app
.然后我做了ng serve
并且在localhost:4200
上工作正常.接下来,我使用ng build
并使用创建的应用程序创建了dist
文件夹.
我使用的是最新的angular-cli,它使用的是webpack.
现在,我想在使用节点的本地环境中使用该应用程序(如果可能的话.如果不能,那么我猜我将在其中编写PHP后端api的WAMP上).我在64位Windows 10机器上.
下一步是什么?我是Nodejs托管设置的新手.
最终,我想为我的办公室创建一个小型应用程序以处理管理工作.局域网中大约有12-15个人会使用它.
我是Nodejs托管设置的新手.
如果您仅出于开发目的而做,我认为您可以使用服务器设计的ad hoc设置不同的流程,以在更改代码时重新编译/重新加载应用程序,而无需每次构建并运行node.js服务器(非常慢的开发流程).我个人将webpack-dev-server与webpack一起使用.
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.
I'm using the latest angular-cli and it uses webpack.
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.
What are the next steps? I am new to nodejs hosting setup.
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.
I am new to nodejs hosting setup.
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)
})
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应用程序-如何在节点上的本地环境中部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!