当前位置:网站首页>1-4 configuration executable script of nodejs installation
1-4 configuration executable script of nodejs installation
2022-04-23 16:58:00 【Endless cake】
NodeJS Configure executable script
First , Get to know , The difference between local module installation and global module installation .
overall situation :
1. All projects can use this module
Inferiority :(1) It is easy to cause version conflicts
(2) Cannot be based on commonJS The module specification , Call use
Just can't js Pass through require Call use
Local :
1. Only the current project can use this module
Inferiority :(1) You can't directly use commands to operate . For example, the command line uses
It is recommended to install local .
Speaking of this , You must be surprised , Why is it possible to execute commands directly when installed globally 》
First remember a command
npm root || npm root -g
View the local or global environment ,npm Installation directory
This is my installation path . I installed it globally . And then according to npm The path to open the folder . You can see the following figure :
You can see npm, There is a vue.cmd The file of , This is what I installed to test . In fact, there is this file , You can use... From the command line vue command . If you want to create a command , Then trigger... From the command line , Just in this directory , Create a cmd The file of , Just edit the content .
in other words , Modules installed in the global directory , Most of them will generate a .cmd The file of , As long as you have this file , Then the file name is an executable command . for example :vue.cmd that vue It's an order
As for how to create your own commands , Copy the following code :
@IF EXIST "%~dp0\node.exe" (
“%~dp0\node.exe” "%~dp0\node_modules\lol\index.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS=;%
node "%~dp0\node_modules\lol\index.js" %*
)
Create your own directory , Just play .
So I see . Only when our module is installed globally can we use the command line , Carry out orders , How to install locally , See the following example :
The following is the of the previous article package.json file , That is, our configuration list .
You can see it in here , There is one scripts An object parameter of , Executable script
{
"name": "c_web", // Module name
"version": "1.0.0", // Version number
"description": "", // Module description
"main": "index.js", // Module main entry file
"scripts": { // Executable script . Here is an example :
"dev": "webpack --mode development", // Packaging in the development environment
"build": "webpack --mode production" // Packaging in a production environment
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": { // Production depends on
"jquery": "^3.4.1"
},
"devDependencies":{ // Development depends on
}
}
Its implementation principle is , Install the module locally , If it supports command operation ( Will be in node_modules Of bin In the middle of xxx.cmd file ) But this file cannot be executed globally . Note here , there node_modules In the current directory .
“dev”: “webpack --mode development”
The attribute name of the command , Just define yourself , Property value is the command script to be executed .
You can see that I have configured two commands .
“scripts”: { // Executable script . Here is an example :
“dev”: “webpack --mode development”, // Packaging in the development environment
“build”: “webpack --mode production” // Packaging in a production environment
},
Through here scripts Execute the commands we define , for example :
npm run dev
npm run build
Such a command actually performs the following steps :
(1) First find scripts Search for
(2) Find and put the following corresponding value ( Execute the script ) perform
(3) When executing a script , Back home node_modules Of bin Search under file , If not , In the npm Search under the global directory of the installation .
版权声明
本文为[Endless cake]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554520256.html
边栏推荐
- STM32__03—初识定时器
- Detailed explanation of the penetration of network security in the shooting range
- 织梦DEDECMS安全设置指南
- PostgreSQL列存与行存
- 扫码登录的原理你真的了解吗?
- Go language, array, string, slice
- Variable length parameter__ VA_ ARGS__ Macro definitions for and logging
- ◰GL-着色器处理程序封装
- Change the password after installing MySQL in Linux
- ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
猜你喜欢
Construction of promtail + Loki + grafana log monitoring system
MySQL master-slave synchronization pit avoidance version tutorial
详解牛客----手套
Detailed explanation of information abstract, digital signature, digital certificate, symmetric encryption and asymmetric encryption
如何建立 TikTok用户信任并拉动粉丝增长
MySQL master-slave replication
File upload and download of robot framework
Nodejs installation and environment configuration
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
How vscode compares the similarities and differences between two files
随机推荐
Loggie source code analysis source file module backbone analysis
An essay on the classical "tear down the wall in thinking"
批量制造测试数据的思路,附源码
websocket
Installing labellmg tutorial in Windows
Selenium IDE and XPath installation of chrome plug-in
Log4j output log information to file
Calculate pie chart percentage
DDT + Excel for interface test
正则过滤内网地址和网段
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
计组 | 【七 输入/输出系统】知识点与例题
Knowledge points and examples of [seven input / output systems]
详解牛客----手套
Paging SQL
Lock lock
Handwritten event publish subscribe framework
【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验
Use case labeling mechanism of robot framework
[registration] tf54: engineer growth map and excellent R & D organization building