简体   繁体   中英

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?

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.

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.

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