npmscripts里的脚本怎么写

1.如何使用NPM作为构建工具

npm Scripts Firstly, we need to figure out how npm can manage our build scripts. As part of npm's core, it has the npm run-script command ( npm run for short). This command dives into your package.json and pulls out the scripts Object. The first argument passed to npm run refers to a property in the scripts object - it will execute the property's value as a command in the operating systems default shell (usually Bash, except on Windows - but we'll get to that later). So let's say you have apackage.json config that looks like this:{"name": "myproject","devDependencies": {"jshint": "latest","browserify": "latest","mocha": "latest" },"scripts": {"lint": "jshint **.js","test": "mocha test/" } } If you run npm run lint - npm will spawn a shell and run jshint **.js . If you run npm run test , npm will spawn a shell and run mocha test/ . The shell environment has your node_modules/.bin folder added to the PATH which means any of the dependencies you have that install binaries will be runnable directly - in other words, no need to put "./node_modules/.bin/jshint **.js" or "$(npm bin)/jshint **.js" . If you run npm run without any arguments it gives you a list of the available commands to run, like so:Available scripts in the user-service package:lint jshint **.js test mocha test/ The npm run shell environment provides lots of helpful features to make sure your scripts are as succinct as they can be. For example the shell's PATH has your./node_modules/.bin/ folder inside of it, meaning any dependencies you install which have binaries can be called directly from a scripts shell. Also, there's a whole slew of super convenient environment variables that npm exposes, such as the currently running task, the package name and version, npm loglevel, and so on. Find them all out by making a script that runs env , and running it, like so:"scripts": {"env": "env" } Shortcut scripts npm also provides a few convinient shortcuts. The npm test , npm start , npm stop commands are all shortcuts for their run equivalents, e.g. npm test is just a shortcut for npm run test . These shortcuts are useful for 2 reasons:These are common tasks that most projects will use, and so it's nice to not have to type as much each time.Much more importanlty - it provides a standard interface within npm for testing, starting and stopping a package. Many CI tools, such as Travis, take advantage of this behaviour by making the default command for a Node.js project npm test . It also makes introducing new developers to your project a breeze, if they know they can simply run scripts like npm test without ever having to read any docs.Pre and Post Hooks Another cool feature about npm is that any script that can be executed also has a set of pre- and post- hooks, which are simply definable in the scripts object. For example, if you execute npm run lint , despite npm having no preconceived idea of what the lint task is, it will immediately run npm run prelint , followed by npm run lint , followed by npm run postlint . The same is true for any command, including npm test ( npm run pretest , npm run test , npm run posttest ). The pre and post scripts are also exit-code-sensitive, meaning if yourpretest script exits with a non-zero exit code, then NPM will immediately stop, and not run the test and posttest scripts. You can't pre- a pre- script though, soprepretest gets ignored. npm also runs the pre- and post- hooks for a few internal commands: install , uninstall , publish , update . You can't override the behaviours for the internal commands - but you can affect their behaviour with pre- and post- scripts. This means you can do cool stuff like:"scripts": {"lint": "jshint **.js","build": "browserify index.js > myproject.min.js","test": "mocha test/","prepublish": "npm run build # also runs npm run prebuild","prebuild": "npm run test # also runs npm run pretest","pretest": "npm run lint" } Passing Arguments Another cool feature with npm (since npm 2.0.0, at least ) is passing argument sets through to the underlying tools. This can be a little complex, but here's an example:"scripts": {"test": "mocha test/","test:xunit": "npm run test -- --reporter xunit" } With this config, we can simply run npm run test - which runs mocha test/ , but we can extend it with custom parameters with a -- prefix. For example npm run test -- anothertest.js will run mocha test/ anothertest.js , or more usefully npm run test -- --grep parser will expand to mocha test/ --grep parser (which runs only the tests with "parser" in the title). In the package.json we have test:xunit which effectively runs mocha test --reporter xunit . This setup can be 。

2.怎么使用这个脚本

首先你要在什么系统上挂。.

win系统的话先

安装git

安装Node.js

然后 点开始菜单-运行-输入CMD

命令行 git clone

等待完成

命令行 cd bilive_client

命令行 npm install

命令行 npm run build

命令行 npm start

OK

linux下

终端下输入 su

输入

apt install npm 或apt-get install npm

安装完npm后安装N管理器

npm i n -g

apt install git或apt-get intall git

安装完成后安装nodejs

npm n stable

命令行 git clone

等待完成

命令行 cd bilive_client

命令行 npm install

命令行 npm run build

命令行 npm start

OK

安桌系统

安装系统分5.0以上和5.0以下

5.0以下比较麻烦点 需要用到 linux ploy

5先说说5.0以上的吧

手机下载 Termux

安装完成后运行Termux

命令行

apt update

apt nodejs

apt install git

命令行 git clone

等待完成

命令行 cd bilive_client

命令行 npm install

命令行 npm run build

命令行 npm start

OK

安装5.0以下

安装linux ploy

在linux ploy安装linux

这里我就不说了,自行百度.

安装完成后 方法同linux

github被屏蔽.git命令用不了..你让在用的人给你发文件吧 方法省略git命令

纯手打。..话说,用手机挂比较好.省电。

npmscripts里的脚本怎么写

转载请注明出处育才学习网 » npmscripts里的脚本怎么写

知识

mysql执行sql修改语句怎么写

阅读(220)

本文主要为您介绍mysql执行sql修改语句怎么写,内容包括mysql数据库执行sql语句怎么写,mysql循环执行sql语句怎么写,mysql数据库怎么执行sql语句。Mysql常用命令详解Mysql安装目录数据库目录/var/lib/mysql/配置文件/usr/share/mysql(mysql.

知识

mysql函数ifelse怎么写

阅读(270)

本文主要为您介绍mysql函数ifelse怎么写,内容包括mysqlifelse怎么写,mysql函数IF的使用方法,mysql怎么使用if.else.来查询。MySql 查询不支持if else流程控制,但是可以使用case函数来实现相同流程控制功能。 下面举例供参考: 根据考生分数判

知识

山货土特产收货公告怎么写

阅读(303)

本文主要为您介绍山货土特产收货公告怎么写,内容包括卖地方特产的店铺公告怎么写,怎么写土特产交易群公告,东北山货土特产分类。1 吃货们请进来吧!来这个充满零食图片王国,吃货们请把自己最爱吃的零食图片发是群相册,此群只能发有零食有关的投

知识

hao帽的hao怎么写

阅读(219)

本文主要为您介绍hao帽的hao怎么写,内容包括hao起衣领的hao字怎么写,hao字怎么写,hao菜的hao字怎么写。薅hāo基本字义1. 拔除:~草。~锄。2. 揪。详细字义〈动〉1. 拔除田草 [weed;pull up;pull out]。如:薅马

知识

reference怎么写哈佛

阅读(264)

本文主要为您介绍reference怎么写哈佛,内容包括什么是哈佛格式的reference,中文的reference用Harvard格式怎么写,什么是哈佛格式的reference。Harvard APA style一般是社科论文用 Boughton, J.M., 2002. The Bretton Woods pr

知识

qq自我介绍怎么写

阅读(239)

本文主要为您介绍qq自我介绍怎么写,内容包括QQ的个人说明,资料怎么写,QQ空间说说自我介绍怎么写,QQ介绍自己的QQ空间语段怎么写。原发布者:kyyige1525个人说明怎么写 比如:为人诚恳,吃苦耐劳,乐观积极,适应能力强;认识问题有超出实际年龄的深度,注

知识

qq互赞介绍怎么写

阅读(227)

本文主要为您介绍qq互赞介绍怎么写,内容包括500人互赞群的介绍怎么写,互赞群介绍怎样写,求个互赞群的介绍怎么写。很荣幸为你介绍几个互赞群每日互赞 2群 3335638223群 31596162245群 已满6群 252914797群 2495228

知识

房产合同编号怎么写

阅读(198)

本文主要为您介绍房产合同编号怎么写,内容包括商品房合同编号多少位数,怎么才能查到我的购房合同编号,如何根据房产合同编号查备案信息。房产合同编号只能在房管部门内部的联网中才能查到,即只有内部工作人员才能查到。一般的房产网是查不到

知识

oracle中怎么写语句

阅读(196)

本文主要为您介绍oracle中怎么写语句,内容包括在oracle数据库中查询语句怎么写,oracle中语句怎么写,请教,Oracle中的语句写法~~~。create table wcy_t1(ID number,InputTime date);insert into wcy_t1 val

知识

residingin怎么写

阅读(207)

本文主要为您介绍residingin怎么写,内容包括什么意思,myfavouriteseason的作文怎么写,NONU.S.。my favourite seasonclass 2, grade 5 ma jialusummer is good, but spri

知识

传家风树新风怎么写

阅读(214)

本文主要为您介绍传家风树新风怎么写,内容包括传家风,立家规,树新风经典短文,传家风立家规树新风征文,传家风,立家规,树新风经典短文。在我的心里,家是菜园,我是菜苗,一个茁壮成长的苗,而陪伴了我十三年的家风则是甘露﹑雨滴.是家风耐心的历经春

知识

大海上的沙滩怎么写

阅读(180)

本文主要为您介绍大海上的沙滩怎么写,内容包括描写“大海沙滩和海水”的句子,描写大海沙滩的句子和海水的句子,怎么写关于想象大海和沙滩的作文急急急。那碧绿的海面,像丝绸一样柔和,微荡着涟猗.从高处看,烟波浩渺,一望无际;而有时,海水就在你的

知识

海藻英文怎么写

阅读(195)

本文主要为您介绍海藻英文怎么写,内容包括海藻用英文怎么表达,海草英语怎么写,海藻用英文怎么表达。UN Secretary-General Ban Ki-moons message for World Oceans Day8 June

知识

号的多音字怎么写

阅读(242)

本文主要为您介绍号的多音字怎么写,内容包括号的多音字儿号的多音字怎么写,号的多音字儿号的多音字怎么写,号的多音字。号[hào] 1. 名称:国~。年~。字~。2. 指人除有名、字之外,另起的别称:别~(如“李白,字太白,~~青莲居士”)。3. 标志:

知识

r脚本帮助文档怎么写

阅读(253)

本文主要为您介绍r脚本帮助文档怎么写,内容包括如何写R语言脚本,如何编写帮助文档,如何写perl脚本的帮助文档。如何写R语言脚本method 11.创建file.R文件2.文件首行#!/path/to/Rscript3.在下面的行中键入R代码4.保

知识

天冀传奇脚本怎么写

阅读(211)

本文主要为您介绍天冀传奇脚本怎么写,内容包括现在买天骥传奇脱机辅助,他脚本是怎么弄的呢是,谁知道怎么制作传奇普通的挂机脚本,玩SF游戏刚进入需要回答问题请问怎么可以脱机挂脚本应该怎么玩S。<升级物品>走到[XXX,XXX,XXX]-------------

知识

shell脚本登录密码怎么写呢

阅读(303)

本文主要为您介绍shell脚本登录密码怎么写呢,内容包括如何在Shell脚本输入密码,如何使用shell脚本修改linux的登陆密码,如何使用shell脚本修改linux的登陆密码。这问题太广泛了。想到其中一种可能,下面答案来自Linux命令大全 网站终端输入密

知识

脚本是怎么写的

阅读(258)

本文主要为您介绍脚本是怎么写的,内容包括脚本是怎么写的,脚本是用什么语言写的,什么是脚本脚本怎么写。脚本(script)是使用一种特定的描述性语言,依据一定的格式编写的可执行文件,又称作宏或批处理文件。同时“脚本”又是编剧术语名词,故事

知识

完美国际魔方脚本怎么写

阅读(291)

本文主要为您介绍完美国际魔方脚本怎么写,内容包括完美国际SF怎么写脚本挂求解,完美国际魔方怎么做,完美国际私服怎么写脚本。等级在40级以上的玩家 每天都能够在各主城的地产官员处领取一个使命徽记 凭借这个使命徽记,玩家可以再次用“命运

知识

页游辅助脚本怎么写

阅读(247)

本文主要为您介绍页游辅助脚本怎么写,内容包括怎样制作页游脚本,怎么制作脚本新浪页游助手游戏工具自,怎样制作页游脚本。一键升级功能体验解放双手轻松游戏、一键自动日常副本,推出魔域永恒游戏辅助脚本、失落魔域、一键自动日常活动,只为广

知识

linuxsql脚本怎么写

阅读(250)

本文主要为您介绍linuxsql脚本怎么写,内容包括如何在linux编写sql脚本,如何在linux编写sql脚本,Linux下如何运行sql脚本。一般以#!/bin/sh开头(不是必须要写,但一定要单独一行),指定执行这个脚本的shell程序(也可以用#!/bin/zsh或其他),

知识

怎么写bash脚本

阅读(220)

本文主要为您介绍怎么写bash脚本,内容包括求写一个bash脚本,如何编写一个shell脚本,Linux如何编写shell脚本。脚本如下。#!/bin/bash# defaultip=192.168.168.168count=3if [ $# -eq 2 ]; t

[/e:loop]