简体   繁体   中英

About MEAN 2 stack using angular-cli

I'm studying MEAN 2.0 . I need to do "ng build" before running "node server.js".

I would like to ask if do I need to do (ng build) everytime I changed something in my angular side? Because when I'm using only angular-cli, when I changed something and my server is still running. It will show the changes. I tried to change something but when I re-run my node server nothing happens.

Yes you need to do ng build before running node server.js.

ng serve :- serves on a server, node server.js :- doesnt serve on the same port, it runs on the port you define in your server.js, it reads from the build folder, which will need updated fies.

Live reload wont work :(

You can 1. write tasks for it 2. write script in package.json which does ng build && node server.js

If you arranged your folder structure to be:

|_server |_ server.js |_ public (angular-cli project) |_ dist |_ src |_ package.json (client) |_package.json(server)

  1. Considering you've the default angular-cli package.json ,
  2. Add concurrently using npm: npm install concurrently --save-dev
  3. All you would need is to add those scripts in server package.json :

"scripts": { "client":"cd public && ng build", "server":"ndoe ./server/server", "start":"concurrently --kill-others \\"npm run client\\" \\"npm run server\\"" }

  1. Now, all you have to do is: npm run start

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM