npm初始

https://www.npmjs.com/package/npm

源加速

设置

1
echo "registry = https://registry.npm.taobao.org">>~/.npmrc

查看当前源

1
npm config get registry

使用

全局安装(-g)

typescript

1
npm install -g typescript

/opt/node/bin/tsc -> /opt/node/lib/node_modules/typescript/bin/tsc
/opt/node/bin/tsserver -> /opt/node/lib/node_modules/typescript/bin/tsserver

卸载

1
npm uninstall -g  typescript
  • iinstall 的简写
  • -g 是全局安装,不带 -g 会安装在个人文件夹
  • -S--save 的简写,安装包信息会写入 dependencies 中;生产阶段,项目运行时的依赖
  • -D--save-dev 的简写,安装包写入 devDependencies 中;开发阶段,只在开发阶段起作用,例如代码提示工具

后台运行

pm2

1
npm install pm2  -g 

pm2 start run.js –name my-api # 命名进程
pm2 list # 显示所有进程状态
pm2 monit # 监视所有进程
pm2 logs # 显示所有进程日志
pm2 stop all # 停止所有进程
pm2 restart all # 重启所有进程
pm2 reload all # 0秒停机重载进程 (用于 NETWORKED 进程)
pm2 stop 0 # 停止指定的进程
pm2 restart 0 # 重启指定的进程
pm2 startup # 产生 init 脚本 保持进程活着
pm2 web # 运行健壮的 computer API endpoint (http://localhost:9615)
pm2 delete 0 # 杀死指定的进程
pm2 delete all # 杀死全部进程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat >run.js<<EOF
const { exec } = require('child_process')
exec('hexo server',(error, stdout, stderr) => {
if(error){
console.log('exec error: ${error}')
return
}
console.log('stdout: ${stdout}')
console.log('stderr: ${stderr}')
})
EOF

pm2 start run.js

vue-tsc: not found

1
2
3
❯ npm install -D vue-tsc
❯ npm install -D vite
❯ npm run build

> zinc-search@0.3.6 build
> vue-tsc –noEmit && vite build

vite v2.9.18 building for production…
✓ 296 modules transformed.
dist/assets/KFOmCnqEu92Fr1Mu4mxM.f2abf7fb.woff 19.87 KiB
dist/assets/KFOkCnqEu92Fr1MmgVxIIzQ.34e9582c.woff 19.96 KiB
dist/assets/KFOlCnqEu92Fr1MmSU5fBBc-.bf14c7d7.woff 19.94 KiB
dist/assets/KFOlCnqEu92Fr1MmWUlfBBc-.e0fd57c0.woff 19.93 KiB
dist/assets/KFOlCnqEu92Fr1MmEU9fBBc-.9ce7f3ac.woff 20.06 KiB
dist/assets/KFOlCnqEu92Fr1MmYUtfBBc-.f6537e32.woff 19.95 KiB
dist/assets/flUhRq6tzZclQEJ-Vdg-IuiaDsNcIhQ8tQ.83be7b2f.woff2 125.35 KiB
dist/assets/flUhRq6tzZclQEJ-Vdg-IuiaDsNa.fd84f88b.woff 161.05 KiB
dist/assets/jsoneditor-icons.45c98bf0.svg 30.74 KiB
dist/index.html 0.42 KiB
dist/assets/Error404.5abc079a.js 0.53 KiB / gzip: 0.37 KiB
dist/assets/MainLayout.c10cd2e1.css 0.31 KiB / gzip: 0.18 KiB
dist/assets/MainLayout.8ebc7735.js 14.18 KiB / gzip: 5.14 KiB
dist/assets/index.3c97601c.css 225.83 KiB / gzip: 40.01 KiB
dist/assets/index.4d6be492.js 2002.85 KiB / gzip: 573.13 KiB

(!) Some chunks are larger than 500 KiB after minification. Consider:

点击打赏
文章目录
  1. 1. 源加速
  2. 2. 使用
    1. 2.1. 全局安装(-g)
    2. 2.2. 卸载
  3. 3. 后台运行
    1. 3.1. pm2
    2. 3.2. vue-tsc: not found
载入天数...载入时分秒... ,