Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue-cli with node

I'm a little bit confused about using Vue and node simultaneously. You can run a Vue-cli application locally by typing npm run dev and it runs on one port, and then I also created an express server file with some routes and that runs on another port. Everything works fine...

But why does Vue-cli have to "run" as if its a server, when it's just client-side code? Does this mean in production I really have to be occupying two ports at the same time for one app?

like image 948
Ryan Bobrowski Avatar asked Feb 01 '18 21:02

Ryan Bobrowski


2 Answers

No, you will npm build your front end and have your express server server it statically. Vue-cli is helpful because it sets up the webpack scaffolding and enables hot reloading.

like image 144
zero298 Avatar answered Oct 21 '22 05:10

zero298


When you use 'npm run dev' you start the webpack server which builds your vue code into javascript code 'dynamically' so you can work on it with hot reload and you will have a 'http://localhost' behaviour instead of a 'file://' etc.

In production build, 'npm run build' you will get a javascript file and an html file to put on your server. You may need some htaccess configs to view your site if you are using vue-router but nothing more than that, you will use those files like a static webpage. For instance, i think it's safe to say that an apache server handles the job that webpack does in development.

like image 24
Reşit Körsu Avatar answered Oct 21 '22 05:10

Reşit Körsu