当前位置:网站首页>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
边栏推荐
- BUG_ me
- File upload and download of robot framework
- Smart doc + Torna generate interface document
- 众昂矿业:萤石浮选工艺
- Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
- ◰GL-着色器处理程序封装
- PostgreSQL column storage and row storage
- How to build tiktok user trust and drive fan growth
- Go language, array, string, slice
- 【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验
猜你喜欢
The new MySQL table has a self increasing ID of 20 bits. The reason is
Grpc gateway based on Ocelot
Deepinv20 installation MariaDB
oracle 中快速获取表的列名列表
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
Dlib of face recognition framework
网络安全之渗透靶场实战详解
Bytevcharts visual chart library, I have everything you want
文件操作《二》(5000字总结篇)
Lock锁
随机推荐
vscode如何比较两个文件的异同
Lock lock
5-minute NLP: text to text transfer transformer (T5) unified text to text task model
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
Path environment variable
蓝桥杯省一之路06——第十二届省赛真题第二场
First knowledge of go language
Change the password after installing MySQL in Linux
伪分布安装spark
众昂矿业:萤石浮选工艺
Solution architect's small bag - 5 types of architecture diagrams
Mock test using postman
Milvus 2.0 détails du système d'assurance de la qualité
关于局域网如何组建介绍
Shell script -- shell programming specification and variables
SQL database
SPC introduction
Detailed explanation of UWA pipeline function | visual configuration automatic test
Easyexcel reads the geographical location data in the excel table and sorts them according to Chinese pinyin
手写事件发布订阅框架