Skip to main content

02 pnpm软件工程化指北(二)初始化项目基本操作

1 初始化pnpm项目

$ mkdir my-project
$ cd my-project
$ pnpm init
Wrote to /Users/root/my-project/package.json

{
"name": "my-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

2 配置pnpm作为项目的唯一管理工具

package.json
{
// ...
"scripts": {
"preinstall": "npx only-allow pnpm",
"test": "echo \"Error: no test specified\" && exit 1"
},
...
}
tip

"preinstall": "npx only-allow pnpm",用于当使用依赖工具进行安装时,就会事先对依赖工具进行检查是否为pnpm,如果不是,则终止安装,并报错提示必须用pnpm.

参考文档