与React Js同时使用npm

时间:2019-01-14 17:16:55

标签: npm concurrently

我有一个使用Node express和React Js创建的项目。服务器(节点)package.json如下。它使用npm run dev一次使用concurrently启动服务器和客户端。服务器使用端口5000,客户端使用端口3000。文件夹结构如下。

/
|
|-mysample
   |
   |-client
   |   |-.env
   |   |-package.json
   |   |-src
   |-server.js
   |-package.json

package.json(mysample)

{
  "name": "mysample",
  "version": "1.0.0",
  "description": "My Sample",
  "main": "server.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "start": "nodemon server.js",
    "server": "nodemon server.js",
    "client": "npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
  "author": "test",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "concurrently": "^4.0.1",
    "express": "^4.16.4",
    "mongoose": "^5.3.8",
  },
  "devDependencies": {
    "nodemon": "^1.18.9"
  }
}

如何使用concurrently npm软件包来启动两个react js项目,这些项目使用端口3000进行管理,而使用8000进行客户端。

   /
    |-ebook_admin
       |
       |-client
       |   |-.env
       |   |-package.json
       |   |-src
       |   |-public
       |   |
       |-package.json
       |-src
       |-public
       |-.env

1 个答案:

答案 0 :(得分:0)

如果我正确理解了您的问题,则可以在https://github.com/chriskavanagh/mern-shopping-list/blob/master/package.json处查看我的一个项目,以了解在https://github.com/chriskavanagh/mern-shopping-list/blob/master/client/package.json处将代理设置为8000端口的时间。

这是后端package.json

"scripts": { "client-install": "npm install --prefix client", "start": "node server.js", "server": "nodemon server.js", "client": "npm start --prefix client", "dev": "concurrently \"npm run server\" \"npm run client\"", "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client", "test": "echo \"Error: no test specified\" && exit 1" },

"proxy": "http://localhost:8000",在您的客户端package.json中