[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 ...
随机推荐
- Elasticsearch入门系列~通过Java一系列操作Elasticsearch
Elasticsearch索引的创建.数据的增删该查操作 上一章节已经在Linux系统上安装Elasticsearch并且可以外网访问,这节主要通过Java代码操作Elasticsearch 1.创建 ...
- (cocos2d-js游戏)測试你的反应速度----------基本逻辑(上)
游戏玩法:点击開始游戏.等待一个随机时间.然后背景颜色会变(在t1时刻),这时候你须要点击屏幕(在t2时刻),游戏结束.你的反应时间就是天t2-t1. 游戏逻辑: 游戏逻辑非常easy,如上图所看到的 ...
- 2.lombok系列2:lombok注解详解
转自:https://www.imooc.com/article/18157 开篇 看到第一篇<初识lombok>你可能意犹未尽,本文我们按照场景来介绍一下常用的注解. 未特别说明,均标注 ...
- nginx+tomcat 架构 HttpServletRequest.getScheme()获取正确的协议
http://blog.csdn.net/ofofw/article/details/46791447
- iOS 中使用 XIB 自定义cell的两种方法以及编译出现常见 的错误 (xcode6.0之后)
一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...
- 模拟登录QQ推断是否须要验证码
老生常谈的问题了,在模拟登录之前,推断是否须要验证码: https://ssl.ptlogin2.qq.com/check? uin=QQ号码&appid=1003903&js_ver ...
- 10.5 android输入系统_Reader线程_使用EventHub读取事件和核心类及配置文件_实验_分析
4. Reader线程_使用EventHub读取事件 使用inotify监测/dev/input下文件的创建和删除 使用epoll监测有无数据上报 细节: a.fd1 = inotify_init(& ...
- 4、runtime电源管理模式(内核文档runtime_pm.txt有详细描述)
系统睡眠模型是让整个系统休眠,而runtime是在系统正常工作的时候单独控制某个设备休眠和唤醒 1. runtime PM流程怎样动态地打开或关闭设备的电源?最简单的方法:在驱动程序里,在open函数 ...
- ECMAScript5和ECMAScript6_浏览器支持情况
ECMAScript5浏览器支持情况: Opera 11.60 Internet Explorer 9* Firefox 4 Safari 5.1** Chrome 13 * IE9不支持严格模式 - ...
- 手动脱KBys Packer(0.28)壳实战
作者:Fly2015 吾爱破解培训第一课选修作业第5个练习程序.在公司的时候用郁金香OD调试该加壳程序的时候出了点问题,可是回家用吾爱破解版的OD一调试,浑身精神爽,啥问题也没有. 首先使用查壳工具对 ...