[NPM] Make npm scripts cross-environment friendly
Unfortunately not all shell commands work across various environments. Two main techniques to support cross-environment scripts is to either use cross-platform commands or to use normalized node packages. In this lesson, we will look at updating an existing set of npm scripts and make sure they work on Mac OS X, Linux, and Windows.
1. Use cross-env
npm i -D cross-env
"test": "cross-env BABEL_ENV=test mocha spec/ --require babel-register",
2. Use 'rimraf' instead of 'rm -rf'
npm i -D rimraf
"postcover": "rimraf .nyc_output",
3. Use 'opn-cli' instead of 'open'
npm i -D opn-cli
"cover:open": "opn coverage/index.html",
4. Windows need double qoutes, to make it works for all envs, we can use \"
"lint:css": "stylelint \"**/*.scss\" --syntax scss",
5. Windows : '%npm_package_version%',
Mac and Linux: '$npm_package_version'
npm i -D cross-var
"prebuild": "cross-var rimraf public/$npm_package_version",
Should be careful when we use '|' pipe and '>' output symbol, we should wrap the whole command in a \"\":
"build:css": "cross-var \"node-sass src/index.scss | postcss -c .postcssrc.json | cssmin > public/$npm_package_version/index.min.css\"",
"scripts": {
"start": "node index.js",
"poststart": "npm run build && npm run server",
"pretest": "npm run lint",
"test": "cross-env BABEL_ENV=test mocha spec/ --require babel-register",
"cover": "nyc npm t",
"postcover": "rimraf .nyc_output",
"cover:open": "opn coverage/index.html",
"lint": "npm-run-all lint:**",
"lint:js": "eslint --cache --fix ./",
"lint:css": "stylelint \"**/*.scss\" --syntax scss",
"lint:css:fix": "stylefmt -R src/",
"watch": "npm-run-all --parallel watch:*",
"watch:test": "npm t -- --watch",
"watch:lint": "onchange \"src/**/*.js\" \"src/**/*.scss\" -- npm run lint",
"build": "npm-run-all build:*",
"prebuild": "cross-var rimraf public/$npm_package_version",
"xbuild:html:mac": "pug --obj data.json src/index.pug --out public/$npm_package_version/",
"xbuild:html:win": "pug --obj data.json src/index.pug --out public/%npm_package_version%/",
"build:html": "cross-var pug --obj data.json src/index.pug --out public/$npm_package_version/",
"xbuild:css:mac": "node-sass src/index.scss | postcss -c .postcssrc.json | cssmin > public/$npm_package_version/index.min.css",
"xbuild:css:win": "node-sass src/index.scss | postcss -c .postcssrc.json | cssmin > public/%npm_package_version%/index.min.css",
"build:css": "cross-var \"node-sass src/index.scss | postcss -c .postcssrc.json | cssmin > public/$npm_package_version/index.min.css\"",
"xbuild:js:mac": "mustache data.json src/index.mustache.js | uglifyjs > public/$npm_package_version/index.min.js",
"xbuild:js:win": "mustache data.json src/index.mustache.js | uglifyjs > public/%npm_package_version%/index.min.js",
"build:js": "cross-var \"mustache data.json src/index.mustache.js | uglifyjs > public/$npm_package_version/index.min.js\"",
"server": "npm-run-all --parallel server:*",
"server:create": "cross-var http-server public/$npm_package_version -p $npm_package_config_port",
"server:launch": "cross-var opn http://localhost:$npm_package_config_port",
"prepush": "npm run lint"
},
[NPM] Make npm scripts cross-environment friendly的更多相关文章
- npm中npm install 始终出错解决办法
npm中npm install 始终出错解决办法 错误信息: C:\Windows\System32>npm install -g gulp npm ERR! Windows_NT 6.1.76 ...
- 一次执行两个npm "start": "concurrently 'npm:dev' 'npm:json-server'"
用的这个程序 concurrently 说是再有异步的时候,&& 就不好使,而且&& 也不能执行npm 只能执行命令 官方地址:https://www.npmjs.co ...
- 遇到 npm WARN npm npm does not support Node.js vx.x.x的解决办法
遇到如下警告 PS C:\Users\Administrator> npm npm WARN npm npm does not support Node.js v9.11.2 npm WARN ...
- npm & private npm service & nrm & nvm
npm & private npm service & nrm & nvm npm server # nrm https://www.cnblogs.com/xgqfrms/t ...
- tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:56281 npm ERR! network This is most likely not a problem with npm itself npm ERR! network and is related to network
tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:56281npm ERR! networ ...
- [Node.js] Configuring npm package.json scripts
With a node package manager's (npm) package.json script property, you can preconfigure common tasks ...
- [NPM] Run npm scripts in parallel
In this lesson we will look at running several npm scripts in parallel. Sometimes you don’t need scr ...
- [NPM] Run npm scripts in series
After creating several npm script it becomes useful to run multiple scripts back-to-back in series. ...
- [NPM] Run npm scripts when files change with onchange
In this lesson we will look at how we can setup our npm scripts to execute when the file system has ...
随机推荐
- 11G、12C Data Guard Physical Standby Switchover转换参考手册
Switchover转换 Step 1: switchover 切换先前检查 (1)确保主备两端log_archive_config和db_unique_name参数都已经正确设置. 需要注意的是 ...
- JS原生选项卡 – 幻灯片效果
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...
- css 0.5px
1. 利用css3新属性scale(好用推荐) 其实现的关键就是利用before或after伪元素,宽高同时设为200%,然后再缩放0.5,自然就是0.5px了 代码如下: div { positon ...
- Redis的高级应用-安全性和主从复制
Redis的服务器命令和键值命令(String,Hash,List,Set,Zset)相对简单,只需查看文档即可. 文档地址: http://www.runoob.com/redis/redis-tu ...
- 【微信】微信获取TOKEN,以及储存TOKEN方法,Spring quartz让Token永只是期
官网说明 access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.开发人员须要进行妥善保存. access_token的存储至少要保留512个字符空间.ac ...
- 自己定义progressdialog载入动画,这里还有旋转的载入条,美团,多个图片动画
自己定义progressdialog载入动画,这里还有旋转的载入条,美团,多个图片动画 下载Demo:http://download.csdn.net/detail/menglele1314/8775 ...
- uva 1463 - Largest Empty Circle on a Segment(二分+三分+几何)
题目链接:uva 1463 - Largest Empty Circle on a Segment 二分半径,对于每一个半径,用三分求出线段到线段的最短距离,依据最短距离能够确定当前R下每条线段在[0 ...
- 芯片SA58672(功放芯片)
1::下面的中文图可能不准: 针对上面的图,数据手册中有一些参数的推导: 这个式子是电压增益的 这个式子是关于截止频率的 典型原理图: 需要电源去耦,能够提高效率. PVDD引脚处的电 ...
- angular 响应式自定义表单控件—注册头像实例
1. 组件继承ControlValueAccessor,ControlValueAccessor接口需要实现三个必选方法 writeValue() 用于向元素中写入值,获取表单的元素的元素值 regi ...
- cURL(wget)—— 测试 RESTful 接口及模拟 GET/POST/PUT/DELETE/OPTIONS 请求
cURL 是一个简单的 http 命令行工具.与最优秀的 Unix 工具一样,在设计之时,cURL 是个小型程序,功能十分专一,而且是故意为之,仅用于访问 http 服务器.(在 Linux 中,可以 ...