项目开发常用总结

158 阅读3分钟

一、配置密钥

1.查看已存在的 SSH 密钥

ED25519 算法

cat ~/.ssh/id_ed25519.pub

RSA算法

cat ~/.ssh/id_rsa.pub

2.生成 SSH 密钥

ED25519 算法

ssh-keygen -t ed25519 -C "<注释内容>"

RSA算法

ssh-keygen -t rsa -C "<注释内容>"

3.将公钥拷贝到ssh公钥设置页面

二、.node版本升降级

由于电脑上code版本使用的是18版,项目上使用14版就要使用到版本升降级 方法

1.安装node版本管理模块n

sudo npm install n -g

2.升级/降级

sudo n 14.2.0

三、安装yarn

npm install -g yarn使用npm 安装yarn

yarn init 开启新工程

yarn install 安装依赖

yarn run/yarn serve/yarn run dev运行脚本

npm 和yarn的区别

1、并行安装:yarn安装包会同时执行多个任务,npm 需等待上一个任务安装完成才能运行下一个任务

2、离线模式:如果你已经安装过一个包,用 yarn 再次安装会从缓存中获取,而 npm 会从网络下载

3、版本锁定:yarn 默认有一个 yarn.lock 文件锁定版本,保证环境统一,而 npm 默认从网络下载最新的最稳定的,版本锁定可以解决包之间版本不兼容问题,npm 也可以通过命令实现版本锁定

4、更简洁的输出:yarn 安装包时输出的信息较少,npm 输出信息冗余

四、npm i过慢

eg:运行到reify:typescript: timing reifyNode:node_modules/@vue/cli/node_modules/vue-codemod/node_modules/rxjs Completed in 6958ms一直卡顿

1.将npm镜像源切换成npm镜像源

npm config set registry https://registry.npm.taobao.org

2.与本地相关资源有冲突

删除对应的文件夹,重新执行npm i

五、git常用总结

1.下载代码git clone 仓库地址

2.git remote add origin git@github.com:yourname/yourfile.git将本地仓库与远程仓库关联

3.回退版本 git reset --hard 版本号

git push -f(强制推送到远程,之前的提交都会被覆盖)

4.在远程分支上创建新分支进行开发

克隆远程分支:git clone <指定分支名> <远程仓库名>

在远程分支上新建分支进行开发 git checkout -b <新分支名字>

将新分支推到远程 git push -u origin <新建分支名字>

查看本地分支状态 git branch -vv

进行本地开发 git status

六、gyp ERR! stack Error: Can't find Python executable "python2.7"

winows10环境

gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (D:\work\4g-box-admin-vue\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (D:\work\4g-box-admin-vue\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack     at callback (D:\work\4g-box-admin-vue\node_modules\graceful-fs\polyfills.js:299:20)
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:191:21)
gyp ERR! System Windows_NT 10.0.22621
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\work\\4g-box-admin-vue\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\work\4g-box-admin-vue\node_modules\node-sass
gyp ERR! node -v v14.18.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@4.14.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\liuwan\AppData\Roaming\npm-cache\_logs\2023-02-04T23_32_46_075Z-debug.log 

运行npm i一直报错,搜索重心放在了Can't find Python executable "python2.7上,直到看到老铁的帖子,搜索npm ERR! node-sass@4.11.0 postinstall: node scripts/build.js找到答案

解决方法: 1.//windows设置变量 sass_binary_site,指向淘宝镜像地址。

set SASS_BINARY_SITE=npm.taobao.org/mirrors/nod… && npm install node-sass

2.//设置全局镜像源:

npm config set sass_binary_site npm.taobao.org/mirrors/nod…