1. Install YARN
npm install -g yarn
2. First we need to set up a directory for our “offline mirroring” storage, which we can do with yarn config
yarn config set yarn-offline-mirror ./npm-packages-offline-cache
An NPM -packages-offline-cache folder is then generated in the current project path to hold the.tgz offline files for the build
3. Move the configuration file to the project path so that the offline mirroring is only used for this project
mv ~/.yarnrc ./
4. Remove the previous node_modules and yarn.lock and rebuild
yarn install
The.tgz zip file can be seen in NPM – Packages – Offline -cache
5. Install node_modules offline
yarn install --offlline
In fact, some scripts need to be updated when executing them. However, because they are off-line, they cannot be updated, which can be ignored. This situation will not occur under the condition of network.
In the real project, we just need to build NPM -Packages-Offline-cache, yarn.lock,.yarnrc, and then execute the offline build command to replace the original NPM install operation.