npm-将已安装的软件包另存为依赖项
问题描述:
我已经通过npm install $package
安装了一些软件包,而没有先设置package.json
.
现在,我想创建一个package.json
文件,但是将所有已安装的软件包保留为依赖项.
简单地运行npm init
不提供此选项,我可以自动实现吗?
I've installed some packages via npm install $package
, without setting up a package.json
first.
Now I would like to create a package.json
file, but keep all installed packages as dependencies.
Simply running npm init
doesn't offer this option, can I achieve this automatically?
答
2016年1月更新
npm 现在支持该功能.我有npm版本 3.5.2 .
npm now supports this out of the box. I have npm version 3.5.2.
因此只有一个 node_modules 文件夹,其中安装了下划线.
so with just a node_modules folder with underscore installed.
npm init --yes
然后:
cat package.json
包含在package.json中
Contained within package.json:
"dependencies": {
"underscore": "^1.8.3"
},