先给一个有初始化设定的例子:
npm init react-app ./my-react-app
这是用 React 初始化来创建一个项目。
如果没有初始化设定,直接使用命令:
npm init
官方文档解释如下:
If the initializer is omitted (by just calling npm init), init will fall back to legacy init behavior. It will ask you a bunch of questions, and then write a package.json for you. It will attempt to make reasonable guesses based on existing fields, dependencies, and options selected. It is strictly additive, so it will keep any fields and values that were already set. You can also use -y/–yes to skip the questionnaire altogether. If you pass --scope, it will create a scoped package.
用谷歌翻译如下:
如果省略初始化程序(通过只调用npm init),init将回退到旧的init行为。 它会问你一堆问题,然后为你写一个package.json。 它将尝试根据所选的现有字段,依赖项和选项进行合理的猜测。 它是严格加法的,因此它将保留已经设置的任何字段和值。 您也可以使用-y / - yes完全跳过调查问卷。 如果你通过–scope,它将创建一个范围包。