返回文章归档

Article

项目中自动适配node版本

2023年3月3日 / 1375fe72-360f-4a5a-95d0-f611eb8703a65 个内容块

.nvmrc

code
v16.18.0
bash
cd ~
vi .zshrc
bash
# place this after nvm initialization! autoload -U add-zsh-hook load-nvmrc() { local node_version="$(nvm version)" local nvmrc_path="$(nvm_find_nvmrc)" if [ -n "$nvmrc_path" ]; then local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") if [ "$nvmrc_node_version" = "N/A" ]; then nvm install elif [ "$nvmrc_node_version" != "$node_version" ]; then nvm use fi elif [ "$node_version" != "$(nvm version default)" ]; then echo "Reverting to nvm default version" nvm use default fi } add-zsh-hook chpwd load-nvmrc load-nvmrc

xjccc.wang

记录前端开发、内容整理和日常思考。

© 2026 xjccc.wang. All rights reserved.

Built with Nuxt, UnoCSS and Sanity.