最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chaining package.json scripts to start Express server and Vue app - Stack Overflow

programmeradmin1浏览0评论

I have built an app using Vue.js and express.js. Currently I have to open two terminal windows and run npm run serve in one and npm start in the other. I want to make the server run after the Vue.js app builds in the same terminal. I read on this article that I can get both scripts to run by chaining the two package.json scripts together, but for the life of me can't figure out how. My project is structured as such:

├── project
├── _frontend
|   ├── package.json
├── backend
|   ├── package.json

I have tried the following ways:

1st try - "serve": "vue-cli-service serve && (cd ../server && npm start)"
2nd try - "serve": "vue-cli-service serve && (cd ../server && npm run start)"
3rd try - "serve": "vue-cli-service serve && (cd ../server) && npm start"

The Vue.js app builds and runs just fine but the server does not start. I tried doing the reverse on the server package.json as well and the server starts but the app does not build. Is this something I can not acplish due to the folder setup or what am I doing wrong?

I have built an app using Vue.js and express.js. Currently I have to open two terminal windows and run npm run serve in one and npm start in the other. I want to make the server run after the Vue.js app builds in the same terminal. I read on this article that I can get both scripts to run by chaining the two package.json scripts together, but for the life of me can't figure out how. My project is structured as such:

├── project
├── _frontend
|   ├── package.json
├── backend
|   ├── package.json

I have tried the following ways:

1st try - "serve": "vue-cli-service serve && (cd ../server && npm start)"
2nd try - "serve": "vue-cli-service serve && (cd ../server && npm run start)"
3rd try - "serve": "vue-cli-service serve && (cd ../server) && npm start"

The Vue.js app builds and runs just fine but the server does not start. I tried doing the reverse on the server package.json as well and the server starts but the app does not build. Is this something I can not acplish due to the folder setup or what am I doing wrong?

Share Improve this question edited Aug 18, 2019 at 7:05 Andrew Vasylchuk 4,7792 gold badges13 silver badges31 bronze badges asked Aug 18, 2019 at 5:43 jaronowjaronow 1131 silver badge9 bronze badges 1
  • 1 Possible duplicate of stackoverflow./questions/30950032/… – Estus Flask Commented Aug 18, 2019 at 6:47
Add a ment  | 

1 Answer 1

Reset to default 7

&& executes mands in series. vue-cli-service serve && cd ../server && npm start won't work as expected because the script stops at vue-cli-service serve until the server is shut down.

For cross-platform script, concurrently or other similar packages can be used to execute mands in parallel:

"serve": "vue-cli-service serve",
"start": "concurrently \"npm run serve\" \"cd ../server && npm start\""
发布评论

评论列表(0)

  1. 暂无评论