1.0.1 • Published 5 months ago

node-auto-fit v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

node-auto-fit

Description

This script can automatically switch the Node.js version in the dev environment,eliminating the need for manual switching with nvm.

Installation

npm i node-auto-fit -D

Usage

1. NVM

First, you need to install nvm to manage Node versions.

2. Create the .nvmrc file

In the root directory of the project, create a file named .nvmrc and write the desired Node.js version in it, for example 18.0.0.

echo "18.0.0" > .nvmrc

3. Edit the package.json file

Find the package.json file and add the serve command in the scripts object like this:

"scripts": {
    "preinstall": "node-auto-fit",
    "start": "node-auto-fit && vite",
    "build": "node-auto-fit && vite build",
  },

Final File Structure Example

  • Root Directory
    • .nvmrc
    • package.json

Contents of the .nvmrc file:

18.0.0

Example part of the package.json file:

{
  "name": "your-project-name",
  "version": "1.0.0",
  "scripts": {
    "preinstall": "node-auto-fit",
    "start": "node-auto-fit && vite",
    "build": "node-auto-fit && vite build",
  },
}

After completing these steps, both the .nvmrc and package.json will be correctly configured, allowing you to use nvm to manage the Node.js version and run scripts.

FAQ

Q: When the Node version specified in the .nvmrc file does not exist, nvm will run the project using the current Node version. issue

A: Due to the current version of nvm not addressing this issue, this project will wait for the PR to be merged in order to fix this bug. pr

1.0.1

5 months ago

1.0.0

5 months ago