简体   繁体   English

链接 package.json 脚本以启动 Express 服务器和 Vue 应用程序

[英]Chaining package.json scripts to start Express server and Vue app

I have built an app using Vue.js and express.js.我已经使用 Vue.js 和 express.js 构建了一个应用程序。 Currently I have to open two terminal windows and run npm run serve in one and npm start in the other.目前我必须打开两个终端窗口并在其中一个运行npm run serve在另一个中npm start I want to make the server run after the Vue.js app builds in the same terminal.我想让服务器在 Vue.js 应用程序在同一终端中构建后运行。 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.我在这篇文章中读到,我可以通过将两个package.json脚本链接在一起来运行这两个脚本,但我一生都无法弄清楚如何运行。 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. Vue.js 应用程序构建并运行得很好,但服务器没有启动。 I tried doing the reverse on the server package.json as well and the server starts but the app does not build.我也尝试在服务器package.json上做相反的事情,服务器启动但应用程序没有构建。 Is this something I can not accomplish due to the folder setup or what am I doing wrong?这是由于文件夹设置而我无法完成的事情还是我做错了什么?

&& executes commands 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. vue-cli-service serve && cd ../server && npm start不会按预期工作,因为脚本在vue-cli-service serve停止,直到服务器关闭。

For cross-platform script, concurrently or other similar packages can be used to execute commands in parallel:对于跨平台脚本,可以使用concurrently或其他类似的包来并行执行命令:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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