与 React Js 同时使用 npm



我有一个使用 Node express 和 React Js 创建的项目。服务器(节点)package.json如下。它同时使用并发启动服务器和客户端,就像使用 npm run dev 一样。服务器使用端口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
如果我

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

这是后端包.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",客户端包中.json

解决方案在这里,首先是并发安装(npm)。

"scripts": {
"client-install": "npm install --prefix client",
"start": "nodemon server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently "cd server && npm server" "npm run client""  

比在你的 CLI 中:npm 运行 dev
这是工作!斯克拉J5

相关内容

  • 没有找到相关文章

最新更新