是包。Json应该手动编辑?像npm这样的程序不能只查看文件,看到“require”语句,然后使用它将必要的条目放入包中吗?json文件吗?有这样的节目吗?
当前回答
1. 选择
如果你是git和GitHub用户:
生成包比NPM init更简单。
else
或者你不喜欢包装。Json模板,生成包或NPM init生成:
你可以通过脚手架应用生成自己的模板,如generate, sails或yeoman。
2. 相关性
这个答案与2018年3月有关。在未来,来自这个答案的数据可能会过时。
这个答案的作者个人在2018年3月使用了generate-package。
3.限制
你需要使用git和GitHub来使用生成包。
4. 示范
例如,我创建了一个空白文件夹sasha-npm-init-vs-generate-package。
4.1. generate-package
命令:
D:\SashaDemoRepositories\sasha-npm-init-vs-generate-package>gen package
[16:58:52] starting generate
[16:59:01] √ running tasks: [ 'package' ]
[16:59:04] starting package
? Project description? generate-package demo
? Author's name? Sasha Chernykh
? Author's URL? https://vk.com/hair_in_the_wind
[17:00:19] finished package √ 1m
package.json:
{
"name": "sasha-npm-init-vs-generate-package",
"description": "generate-package demo",
"version": "0.1.0",
"homepage": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package",
"author": "Sasha Chernykh (https://vk.com/hair_in_the_wind)",
"repository": "Kristinita/sasha-npm-init-vs-generate-package",
"bugs": {
"url": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package/issues"
},
"license": "MIT",
"engines": {
"node": ">=4"
},
"scripts": {
"test": "mocha"
},
"keywords": [
"generate",
"init",
"npm",
"package",
"sasha",
"vs"
]
}
4.2. npm init
D:\SashaDemoRepositories\sasha-npm-init-vs-generate-package>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (sasha-npm-init-vs-generate-package)
version: (1.0.0) 0.1.0
description: npm init demo
entry point: (index.js)
test command: mocha
git repository: https://github.com/Kristinita/sasha-npm-init-vs-generate-package
keywords: generate, package, npm, package, sasha, vs
author: Sasha Chernykh
license: (ISC) MIT
About to write to D:\SashaDemoRepositories\sasha-npm-init-vs-generate-package\package.json:
{
"name": "sasha-npm-init-vs-generate-package",
"version": "0.1.0",
"description": "npm init demo",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Kristinita/sasha-npm-init-vs-generate-package.git"
},
"keywords": [
"generate",
"package",
"npm",
"package",
"sasha",
"vs"
],
"author": "Sasha Chernykh",
"license": "MIT",
"bugs": {
"url": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package/issues"
},
"homepage": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package#readme"
}
Is this ok? (yes) y
{
"name": "sasha-npm-init-vs-generate-package",
"version": "0.1.0",
"description": "npm init demo",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Kristinita/sasha-npm-init-vs-generate-package.git"
},
"keywords": [
"generate",
"package",
"npm",
"package",
"sasha",
"vs"
],
"author": "Sasha Chernykh",
"license": "MIT",
"bugs": {
"url": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package/issues"
},
"homepage": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package#readme"
}
我认为,这个generate-package更简单,这个npm init。
5. 定制
创建你自己的包。Json模板,见生成和yeoman的例子。
其他回答
您现在可以使用Yeoman -现代Web应用程序脚手架工具节点终端使用3个简单的步骤。
首先,你需要安装yo和其他必要的工具:
$ npm install -g yo bower grunt-cli gulp
要构建一个web应用程序,请安装generator-webapp generator:
$ npm install -g generator-webapp // create scaffolding
跑啊,然后…你都完成了:
$ yo webapp // create scaffolding
Yeoman可以为您的整个web应用程序或控制器和模型编写样板代码。它可以启动实时预览web服务器进行编辑和编译;不仅如此,您还可以运行您的单元测试,最小化和连接您的代码,优化图像,等等……
Yeoman (yo) -脚手架工具,提供特定于框架的脚手架生态系统,称为生成器,可用于执行前面提到的一些乏味的任务。
Grunt / gulp -用于构建、预览和测试项目。
Bower -用于依赖管理,因此您不再需要手动下载前端库。
基于Pylinux的回答,下面是针对Windows操作系统的解决方案,
dir node_modules > abc.txt
FOR /F %k in (abc.txt) DO npm install --save
希望能有所帮助。
运行npm init -y使你的包。Json和所有默认值。 然后您可以更改包。相应的json 通过避免在npm init中的每个命令上都按enter键,可以节省很多时间
命令行:
npm init
将创建包。json文件
安装,更新和卸载依赖包到包。json文件:
命令行:
npm install <pkg>@* --save
将自动将依赖项下的包的最新版本添加到包中。json文件
EX:
npm install node-markdown@* --save
命令行:
npm install <pkg> --save
还会自动将依赖项下的包的最新版本添加到包中。json文件
如果你需要一个包的特定版本,使用这个命令行:
npm install <pkg>@<version> --save
将自动添加特定版本的包在依赖到包。json文件
EX:
npm install koa-views@1.0.0 --save
如果你需要一个包的特定版本范围,使用这个命令行:
npm install <pkg>@<version range>
将自动在依赖项下的版本范围内为包添加最新版本到包中。json文件
EX:
npm install koa-views@">1.0.0 <1.2.0" --save
有关如何为包npm Doc编写version的更多细节
命令行:
npm update --save
将包更新为包。Json文件,并将自动添加更新版本下的所有包依赖到包。json文件
命令行:
npm uninstall <pkg> --save
将自动将包从依赖项移到包中。并从node_module文件夹中删除包
1. 选择
如果你是git和GitHub用户:
生成包比NPM init更简单。
else
或者你不喜欢包装。Json模板,生成包或NPM init生成:
你可以通过脚手架应用生成自己的模板,如generate, sails或yeoman。
2. 相关性
这个答案与2018年3月有关。在未来,来自这个答案的数据可能会过时。
这个答案的作者个人在2018年3月使用了generate-package。
3.限制
你需要使用git和GitHub来使用生成包。
4. 示范
例如,我创建了一个空白文件夹sasha-npm-init-vs-generate-package。
4.1. generate-package
命令:
D:\SashaDemoRepositories\sasha-npm-init-vs-generate-package>gen package
[16:58:52] starting generate
[16:59:01] √ running tasks: [ 'package' ]
[16:59:04] starting package
? Project description? generate-package demo
? Author's name? Sasha Chernykh
? Author's URL? https://vk.com/hair_in_the_wind
[17:00:19] finished package √ 1m
package.json:
{
"name": "sasha-npm-init-vs-generate-package",
"description": "generate-package demo",
"version": "0.1.0",
"homepage": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package",
"author": "Sasha Chernykh (https://vk.com/hair_in_the_wind)",
"repository": "Kristinita/sasha-npm-init-vs-generate-package",
"bugs": {
"url": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package/issues"
},
"license": "MIT",
"engines": {
"node": ">=4"
},
"scripts": {
"test": "mocha"
},
"keywords": [
"generate",
"init",
"npm",
"package",
"sasha",
"vs"
]
}
4.2. npm init
D:\SashaDemoRepositories\sasha-npm-init-vs-generate-package>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (sasha-npm-init-vs-generate-package)
version: (1.0.0) 0.1.0
description: npm init demo
entry point: (index.js)
test command: mocha
git repository: https://github.com/Kristinita/sasha-npm-init-vs-generate-package
keywords: generate, package, npm, package, sasha, vs
author: Sasha Chernykh
license: (ISC) MIT
About to write to D:\SashaDemoRepositories\sasha-npm-init-vs-generate-package\package.json:
{
"name": "sasha-npm-init-vs-generate-package",
"version": "0.1.0",
"description": "npm init demo",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Kristinita/sasha-npm-init-vs-generate-package.git"
},
"keywords": [
"generate",
"package",
"npm",
"package",
"sasha",
"vs"
],
"author": "Sasha Chernykh",
"license": "MIT",
"bugs": {
"url": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package/issues"
},
"homepage": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package#readme"
}
Is this ok? (yes) y
{
"name": "sasha-npm-init-vs-generate-package",
"version": "0.1.0",
"description": "npm init demo",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Kristinita/sasha-npm-init-vs-generate-package.git"
},
"keywords": [
"generate",
"package",
"npm",
"package",
"sasha",
"vs"
],
"author": "Sasha Chernykh",
"license": "MIT",
"bugs": {
"url": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package/issues"
},
"homepage": "https://github.com/Kristinita/sasha-npm-init-vs-generate-package#readme"
}
我认为,这个generate-package更简单,这个npm init。
5. 定制
创建你自己的包。Json模板,见生成和yeoman的例子。
推荐文章
- 查询JSON类型内的数组元素
- ReferenceError: description没有定义NodeJs
- 将JSON字符串转换为HashMap
- 将JsonNode转换为POJO
- Json_encode()转义正斜杠
- 将一个二进制的NodeJS Buffer转换为JavaScript的ArrayBuffer
- 如何写一个JSON文件在c# ?
- AngularJS只适用于单页应用程序吗?
- 在序列化和反序列化期间JSON属性的不同名称
- 如何在vue-cli项目中更改端口号
- 如何查看npm包的大小?
- 为什么PHP的json_encode函数转换UTF-8字符串为十六进制实体?
- 同步和异步编程(在node.js中)的区别是什么?
- 如何编辑通过npm安装的节点模块?
- Ajax会调用什么样的响应,比如'for (;;);{json data}的意思?