Installation of node js and use of npm package

Node js installation

Download official website address: node.js
Download method:
[Note] If the computer system version is relatively high, you can choose to download the latest version, if the computer system version is low, you can choose the following method
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Test whether the installation was successful

2-1. Open the command line window (cmd)
(1) Enter cmd in the search bar of the start menu
and press Enter directly (2) In any blank place of the computer, press the shift key + the right mouse button === "The menu appears === 》 Open the command line window here (W)
Insert picture description here

2-2 Enter the command to test in the command line window. Enter
node -v
and press Enter. If the detailed nodejs version number appears, it proves that the nodejs installation is successful.

If you enter the command and press Enter, the following prompt message appears: It proves that either the relevant command tool is not installed, or the installation
fails.'xxx' is not an internal or external command, nor is it an executable program or batch file.
Insert picture description here

After installation, create a folder locally to store the moudel module

step 1

Insert picture description here

Step 2

Insert picture description here

Step 3 Management commands for npm package

Install npm along with the installation of nodejs to
test whether npm can be used.
Enter npm -v and press Enter to use the
Insert picture description here
es6 module: Use a webapck packaging tool

Step 4 Enter nmp init -y in the command window and press Enter

Insert picture description here

Step 5 Enter nmp install (downloaded plug-in name) in the command window (eg: webpack webpack-cli)--save and press enter

Insert picture description here
Insert picture description here
Insert picture description here
The node_moduels file in the folder exists when it is in use and can be deleted when not in use. This file is relatively large and will take up a lot of space if copied. If you still need to use it after deleting it, you can enter npm i in the command line and press Enter. Recovery When
copying files: Do not copy node_modules (this is where third-party packages are stored and can be installed and deleted at any time)
Installation dependency:
execute the npm i command in the root directory of the project (the directory where the package.json file is located)
Insert picture description here

All the above preparations have been done, create a new folder in the directory folder

Insert picture description here
Insert picture description here

Open the zhaozhizu folder through vscode

Create an entry file in the src folder, which is a js file
Insert picture description here

Enter the code in index.js, enter the command npm run build in the command window and press Enter

Webpack related commands:
npm run build
npm run dev

Insert picture description here
There will be a main js file in this file. Enter the new execution code in the index file. By calling the npm run bulid command in the command window and pressing Enter, it will be output in the main js file
Insert picture description here
Insert picture description here
in the src folder, index The file belongs to the entry file, multiple files can be created in src, and these module files can be linked to each other

Guess you like

Origin blog.csdn.net/weixin_53125457/article/details/114893736