在父package.json中具有公共依赖性的多模块npm构建

时间:2019-05-08 03:02:44

标签: reactjs npm

我有一个带有reactjs的项目,该项目具有父文件夹和子文件夹。父文件夹和每个子文件夹都包含package.json。

在父级上进行npm安装时,我也在构建子文件夹。但是问题是npm istall需要花费更多时间,因为在子文件夹package.json中有重复的条目作为父package.json。

ParentFolder
     --SubFolder1
          package.json
      --SubFolder2
          package.json
    package.json

父package.json

{
  "name": "parent",
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.0"
  },
  "scripts": {
    "subfolder1-build": "cd  SubFolder1 && npm install && npm run-script build",
    "subfolder2-build": "cd SubFolder1  && npm install && npm run-script build"
  }
}

Subfolder1 package.json

{
  "name": "Subfolder1",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

在subfolder1 package.json中,我具有与父package.jso相同的依赖项

"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.0"

我是npm的新手。是否可以在父package.json中添加公共依赖项,并仅在子文件夹package.json中添加所需的依赖项,以及如何在子文件夹package.json中引用父npm模块?

0 个答案:

没有答案