简体   繁体   English

有没有办法在 package.json 中对依赖项进行分组?

[英]Is there a way to group dependencies in package.json?

I have a package.json我有一个 package.json

"dependencies": {
    "@babel/core": "7.2.2",
    "@babel/preset-env": "7.3.1",
    "@babel/register": "7.0.0",
    "babel-loader": "8.0.5",
    "browser-sync": "^2.26.0",
    "@hot-loader/react-dom": "^16.8.6",
    "react": "^16.10.1",
    "react-dom": "^16.10.1",
    "react-hot-loader": "^4.12.13",
    "webpack": "^4.41.0",
    "glob": "^7.1.6",
    "args": "^5.0.1",
    "webpack-dev-middleware": "^3.7.2",
    "webpack-hot-middleware": "^2.25.0"
  },

I have two build processes:我有两个构建过程:

Build A - standard app.构建 A - 标准应用程序。

git clone <myrepo.git>
npm install
npm run build-app
deploy

Build B - static files构建 B - 静态文件

git clone <myrepo.git>
npm install glob args // I want to read this from package.json
npm run build-static
deploy-static

What I would like is to group dependencies into two groups.我想要的是将依赖项分为两组。

The reason is installing all the dependencies takes about ~2mins.原因是安装所有依赖项大约需要大约 2 分钟。 For second build task, I only need 2-3 packages which takes less than 10 seconds.对于第二个构建任务,我只需要 2-3 个不到 10 秒的包。 Currently, I have npm install glob args hardcoded in my build program.目前,我在我的构建程序中硬编码了npm install glob args I want to read it from the same package.json.我想从同一个 package.json 中读取它。


I cannot use dependencies vs dependencies because I have some dependencies used just for development and use the flag npm install --production to install only the required dependencies (without devDependencies).我不能使用依赖项 vs 依赖项,因为我有一些依赖项仅用于开发,并使用标志npm install --production仅安装所需的依赖项(没有 devDependencies)。

You can surely group them;你当然可以将它们分组; there are two types of dependencies, one's dev and the other one is production.有两种类型的依赖项,一种是开发的,另一种是生产的。 Here's a reference: https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file这是一个参考: https : //docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file

If you want to create more than two, check this package out: https://www.npmjs.com/package/group-dependencies如果要创建两个以上,请查看此包: https : //www.npmjs.com/package/group-dependencies

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

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