Recently, projects have to switch to intranet development. The most troublesome thing is code migration and project restart. All front-end projects depend on NPM install installation. It’s needless to say that the external network. Here are several methods for restarting internal network projects:
1. The whole project is compressed and copied into the intranet, which is simple and rough
Do not remove the node when compressing the extranet project_ Modules folder. Then copy it into the intranet and directly NPM start up.
Note: this method can be used only when the project node versions of Intranet and extranet are consistent.
View node version command line: node – V
However, the node of the intranet is generally installed on Disk C, and we only have our own user folder permissions under disk D (that’s the trouble). There is no way to install other node versions on the intranet. You can only reinstall a node version corresponding to the intranet, NPM install, and then copy it in. Fortunately, node_ The dependencies in the modules folder will not move once the project is formed, but unfortunately, if the project introduces new dependencies in the future, you have to repeat this operation. If it is too troublesome, please see method 2.
2. Set the NPM source and it’s done
The NPM source address of the general extranet is https://registry.npmjs.org/ Or Taobao image http://registry.npm.taobao.org/ 。 When switching to intranet development, the source address of the extranet cannot be used here. Generally, there will be NPM private library in the company intranet. Set and change the source address to the address of the company’s NPM private library.
npm config set registry http://ip Address: Port No. / XXXX / XXXX
Then you can perform NPM install like the Internet. However, it is easy to encounter node sass installation failure at this time. It is estimated that it is blocked by the wall. However, there is no way to switch to other NPM sources on the intranet, so you can only download the node sass package on the extranet and then move it to the intranet for installation. Please see the following operation for details. If not, please ignore it.
(1) View the node sass installation package to be downloaded from the command line, as shown in Figure 1.
node -p "[process.platform,process.arch,process.versions.modules].join('-')"
Figure 1 what I need is a win32-x64-72 package
(2) go to the official GitHub Library of node sass to download the release package. Portal:https://github.com/sass/node-sass/releases。 Find the corresponding release package name, as shown in Figure 2. After downloading, copy it to a folder on the intranet.
Figure 2 download the release package you need. Take the red box in the figure as an example and the node suffix file
(3) Setting environment variables
Configure sass in user variable_ BINARY_ Path. The value is the intranet file storage path of the downloaded releases package.
Configure path and add an intranet file storage path of the downloaded releases package after the existing value (don’t forget to add a semicolon).
set SASS_ BINARY_ Path = x: \ XXXX \ XXXX \ XXXX // release package intranet storage path
If there is still a problem with the installation, please pay attention to whether there is a problem with the path configuration of the environment variable, or it may be necessary to restart the computer before the environment variable takes effect.
Figure 3 pixel residue, you can only barely look at it. The release package of win32-x64-59 is required for intranet
Although it’s a little more troublesome than method 1, it’s done. The subsequent operation is almost the same as that of the Internet.