Settings (.npmrc)
pnpm mendapatkan konfigurasinya dari baris perintah, variabel lingkungan, dan file .npmrc
.
Perintah pnpm config
dapat digunakan untuk memperbarui dan mengedit konten file pengguna dan global dari .npmrc
.
Empat file yang relevan adalah:
- file konfigurasi per proyek (
/path/to/my/project/.npmrc
) - file konfigurasi per ruang kerja (direktori yang berisi file
pnpm-workspace.yaml
) - file konfigurasi per pengguna (
~/.npmrc
) - file konfigurasi global (
/etc/npmrc
)
Semua file .npmrc
adalah parameter key = value
berformat INI.
Values in the .npmrc
files may contain env variables using the ${NAME}
syntax. The env variables may also be specified with default values. Using ${NAME-fallback}
will return fallback
if NAME
isn't set. ${NAME:-fallback}
will return fallback
if NAME
isn't set, or is an empty string.
Pengaturan Pengangkatan Ketergantungan
hoist
- Default: true
- Ketik: boolean
When true
, all dependencies are hoisted to node_modules/.pnpm/node_modules
. This makes unlisted dependencies accessible to all packages inside node_modules
.
hoist-workspace-packages
- Default: true
- Ketik: boolean
When true
, packages from the workspaces are symlinked to either <workspace_root>/node_modules/.pnpm/node_modules
or to <workspace_root>/node_modules
depending on other hoisting settings (hoist-pattern
and public-hoist-pattern
).
hoist-pattern
- Default: ['*']
- Type: string[]
Tells pnpm which packages should be hoisted to node_modules/.pnpm/node_modules
. By default, all packages are hoisted - however, if you know that only some flawed packages have phantom dependencies, you can use this option to exclusively hoist the phantom dependencies (recommended).
Contohnya:
hoist-pattern[]=*eslint*
hoist-pattern[]=*babel*
You may also exclude patterns from hoisting using !
.
Contohnya:
hoist-pattern[]=*types*
hoist-pattern[]=!@types/react
public-hoist-pattern
- Default: []
- Type: string[]
Unlike hoist-pattern
, which hoists dependencies to a hidden modules directory inside the virtual store, public-hoist-pattern
hoists dependencies matching the pattern to the root modules directory. Hoisting to the root modules directory means that application code will have access to phantom dependencies, even if they modify the resolution strategy improperly.
This setting is useful when dealing with some flawed pluggable tools that don't resolve dependencies properly.
Contohnya:
public-hoist-pattern[]=*plugin*
Note: Setting shamefully-hoist
to true
is the same as setting public-hoist-pattern
to *
.
You may also exclude patterns from hoisting using !
.
Contohnya:
public-hoist-pattern[]=*types*
public-hoist-pattern[]=!@types/react
shamefully-hoist
- Default: false
- Type: Boolean
By default, pnpm creates a semistrict node_modules
, meaning dependencies have access to undeclared dependencies but modules outside of node_modules
do not. With this layout, most of the packages in the ecosystem work with no issues. However, if some tooling only works when the hoisted dependencies are in the root of node_modules
, you can set this to true
to hoist them for you.
Node-Modules Settings
modules-dir
- Default: node_modules
- Type: path
The directory in which dependencies will be installed (instead of node_modules
).
node-linker
- Default: isolated
- Type: isolated, hoisted, pnp
Defines what linker should be used for installing Node packages.
- isolated - dependencies are symlinked from a virtual store at
node_modules/.pnpm
. - hoisted - a flat
node_modules
without symlinks is created. Same as thenode_modules
created by npm or Yarn Classic. One of Yarn's libraries is used for hoisting, when this setting is used. Legitimate reasons to use this setting:- Your tooling doesn't work well with symlinks. A React Native project will most probably only work if you use a hoisted
node_modules
. - Your project is deployed to a serverless hosting provider. Some serverless providers (for instance, AWS Lambda) don't support symlinks. An alternative solution for this problem is to bundle your application before deployment.
- If you want to publish your package with
"bundledDependencies"
. - If you are running Node.js with the --preserve-symlinks flag.
- Your tooling doesn't work well with symlinks. A React Native project will most probably only work if you use a hoisted
- pnp - no
node_modules
. Plug'n'Play is an innovative strategy for Node that is used by Yarn Berry. It is recommended to also setsymlink
setting tofalse
when usingpnp
as your linker.
symlink
- Default: true
- Type: Boolean
When symlink
is set to false
, pnpm creates a virtual store directory without any symlinks. It is a useful setting together with node-linker=pnp
.
enable-modules-dir
- Default: true
- Type: Boolean
When false
, pnpm will not write any files to the modules directory (node_modules
). This is useful for when the modules directory is mounted with filesystem in userspace (FUSE). There is an experimental CLI that allows you to mount a modules directory with FUSE: @pnpm/mount-modules.
virtual-store-dir
- Default: node_modules/.pnpm
- Types: path
The directory with links to the store. All direct and indirect dependencies of the project are linked into this directory.
This is a useful setting that can solve issues with long paths on Windows. If you have some dependencies with very long paths, you can select a virtual store in the root of your drive (for instance C:\my-project-store
).
Or you can set the virtual store to .pnpm
and add it to .gitignore
. This will make stacktraces cleaner as paths to dependencies will be one directory higher.
NOTE: the virtual store cannot be shared between several projects. Every project should have its own virtual store (except for in workspaces where the root is shared).
virtual-store-dir-max-length
- Asali:
- On Linux/macOS: 120
- On Windows: 60
- Types: number
Sets the maximum allowed length of directory names inside the virtual store directory (node_modules/.pnpm
). You may set this to a lower number if you encounter long path issues on Windows.