• Watch for changes to the styles.scss file and automatically compile it to the css file.
  • Run multiple NPM scripts in parallel using parallelshell NPM module.

Watching for Changes and Parallelshell

  • First, we install two NPM packages onchange and parallelshell as follows:

  npm install --save-dev onchange@3.3.0 parallelshell@3.0.2

  • Then, add the following two script items to package.json if you are doing the exercise on a MacOS computer or a Linux computer:

  "watch:scss": "onchange \"css/*.scss\" -- npm run scss",

"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""

"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\"\"npm run lite\""
},

NPM Scripts Part 1

Objectives and Outcomes

In this exercise, you will learn to set up NPM scripts by modifying the package.json file. At the end of this exercise, you will be able to:

  • Watch for changes to the styles.scss file and automatically compile it to the css file.
  • Run multiple NPM scripts in parallel using parallelshell NPM module.

Moving JS to Script file

  • Create a folder named js and in that folder create a file named scripts.js.
  • Open index.html and from this file cut out all the JQuery script that we added to it and move the code to the scripts.jsfile that we created above.
  • Then, update the index.html file to include the scripts.js file by adding the following line:
1
 
 
 
<scriptsrc="js/scripts.js"></script>
 
 
 
  • Add the same line to the scripts block in aboutus.html and contactus.html:

Watching for Changes and Parallelshell

  • First, we install two NPM packages onchange and parallelshell as follows:
1
 
 
 
npm install --save-dev onchange@3.3.0 parallelshell@3.0.2
 
 
 
  • Then, add the following two script items to package.json if you are doing the exercise on a MacOS computer or a Linux computer:
1
2
 
 
 
"watch:scss": "onchange 'css/*.scss' -- npm run scss",
"watch:all": "parallelshell 'npm run watch:scss' 'npm run lite'"
 
 
 
  • NOTE: If you are doing the exercise on a Windows computer, please use the following two script items instead of the above:
1
2
 
 
 
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\"\"npm run lite\""
 
 
 
  • You will also update the start script as follows:
1
 
 
 
"start": "npm run watch:all",
 
 
 
  • Then, type the following at the prompt to start watching for changes to the SCSS file, compile it to CSS, and run the server:
1
 
 
 
npm start
 
 
 

NPM Scripts -- onchange parallelshell的更多相关文章

  1. NPM Scripts 2 -- rimraf copyfiles imagemin usemin htmlmin uglifyjs

    NPM Scripts Part 2 Objectives and Outcomes In this exercise you will learn to build a distribution f ...

  2. [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 ...

  3. npm Scripts使用教程【译】

    Why npm Scripts? 原文发表于 2016.2.12,原文地址: https://css-tricks.com/why-npm-scripts/ 以下是访客Damon Bauer发布的一篇 ...

  4. npm scripts 助力前端开发,实时刷新浏览器

    用browser-sync或者lite-server来监控文件的改变,当文件改变时,就自动刷新浏览器. 用node-sass来实时编译scss文件. 用parallelshell来异步执行npm sc ...

  5. npm scripts + webpack 实践经验(React、Nodejs)

    最近用Webpack+npm scripts+Mongodb+Nodejs+React写了个后台项目,在用Webpack构建过程中遇到了许多坑,就写出来分享一下. 构建工具五花八门,想当年刚学会Gru ...

  6. [NPM] Pull out npm scripts into another file with p-s

    A technique you might use once you start having lots of npm scripts is to use a node package that al ...

  7. [NPM] Make npm scripts cross-environment friendly

    Unfortunately not all shell commands work across various environments. Two main techniques to suppor ...

  8. windows下npm scripts不能执行的问题

    最近在学webpack为了方便把运行脚本写入package.json文件中,如下: "scripts": { "start": "webpack-de ...

  9. 5.npm scripts 使用指南

    简单介绍 scripts里面的 "start": "node app" npm run start 相当于 node app { "name" ...

随机推荐

  1. Python 类型和对象(转)

    译文:http://wiki.woodpecker.org.cn/moin/PyTypesAndObjects 原文:http://www.cafepy.com/article/python_attr ...

  2. Navicat工具、pymysql模块、数据备份

    IDE工具介绍(Navicat) 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具,我们使用Navicat工具,这个工具本质上就是一个socket客户端,可视化的连接mys ...

  3. mysql 正则表达式 regexp rlike not rlike

    regexp   rlike    not rlike 今天在上班的时候突然遇到了一个问题,C+组的同事要删除mysql里面的一些特殊数据,想要正则进行匹配.于是问我,没想到还真的把我难住了,问题如下 ...

  4. SyntaxError: Missing parentheses in call to 'print'. Did you mean print('XXXXXX')?

    因为Python3中取消了以前Python 2中的语法. 所以Python 3再使用python2的语法格式就会报错 错误信息中提示需要加上括号,字符串可以用单引号或双引号括起来 这样就不会报错了.

  5. 从原型链看DOM--Element类型

    Element类型用于表现XML或HTML元素,提供对元素标签名,子节点及特性的访问.原型链的继承关系为 某节点元素.__proto__->(HTML某元素Element.prototype)- ...

  6. linux文件编程----系统调用

    linux中文件编程可以使用两种方法: 1).linux系统调用 2).C语言库函数 前者依赖于linux系统,后者与操作系统是独立的. 在 linux系统中,所有打开的文件也对应一个数字,这个数字由 ...

  7. matplotlib的一些代码

    Matplotlib Python 画图教程 (莫烦Python)_演讲•公开课_科技_bilibili_哔哩哔哩 https://www.bilibili.com/video/av16378354/ ...

  8. Curl https 访问

    如果访问https的网页,出现: curl: (60) SSL certificate problem: unable to get local issuer certificate 将 将 CURL ...

  9. mysql数据库从删库到跑路之mysql库操作

    一 知识储备 MySQL数据库基本操作知识储备 数据库服务器:一台计算机(对内存要求比较高) 数据库管理系统:如mysql,是一个软件 数据库:oldboy_stu,相当于文件夹 表:student, ...

  10. MySQL临时表的简单用法(复制)

      当工作在非常大的表上时,你可能偶尔需要运行很多查询获得一个大量数据的小的子集,不是对整个表运行这些查询,而是让MySQL每次找出所需的少数记录,将记录选择到一个临时表可能更快些,然后在这些表运行查 ...