Movatterモバイル変換


[0]ホーム

URL:


Skip to searchSkip to content

Site navigation

npm-init

create a package.json file

Select CLI Version:

See DetailsTable of contents

Synopsis

npm init[--force|-f|--yes|-y|--scope]
npm init<@scope>(same as`npx<@scope>/create`)
npm init[<@scope>/]<name>(same as`npx[<@scope>/]create-<name>`)

Examples

Create a new React-based project usingcreate-react-app:

$npm init react-app ./my-react-app

Create a newesm-compatible package usingcreate-esm:

$mkdir my-esm-lib&&cd my-esm-lib
$npm init esm--yes

Generate a plain old package.json using legacy init:

$mkdir my-npm-pkg&&cd my-npm-pkg
$git init
$npm init

Generate it without having it ask any questions:

$npm init-y

Description

npm init <initializer> can be used to set up a new or existing npm package.

initializer in this case is an npm package namedcreate-<initializer>, which will be installed bynpx, and then have its main bin executed -- presumably creating or updatingpackage.json and running any other initialization-related operations.

The init command is transformed to a correspondingnpx operation as follows:

  • npm init foo ->npx create-foo
  • npm init @usr/foo ->npx @usr/create-foo
  • npm init @usr ->npx @usr/create

Any additional options will be passed directly to the command, sonpm init foo --hello will map tonpx create-foo --hello.

If the initializer is omitted (by just callingnpm 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.

See Also

Edit this page on GitHub
1 contributorethomson
Last edited byethomson onSeptember 22, 2020

[8]ページ先頭

©2009-2025 Movatter.jp