• 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. Django logging模块

    一.Django logging配置 1.在setting.py中配置 # 日志文件存放路径 BASE_LOG_DIR = os.path.join(BASE_DIR, "log" ...

  2. Oracle中to_number()函数的用法

    to_number()函数是oracle中常用的类型转换函数之一,是将一些处理过的按一定格式编排过的字符串变回数值型的格式. 1.to_number()函数可以将char或varchar2类型的str ...

  3. Python学习笔记(一)数据类型

    一.整型和浮点型 Python可以处理任意大小的整数,当然包括负整数,在程序中的表示方法和数学上的写法一模一样 age=10 num=-35 score=98.8 二.布尔类型 布尔值和布尔代数的表示 ...

  4. Hbase架构和读写流程

    转载自:http://www.cnblogs.com/muzili-ykt/p/muzili_ykt.html 在HBase读写时,相同Cell(RowKey/ColumnFamily/Column相 ...

  5. 8种主要排序算法的C#实现 (一)

    简介 排序算法是我们编程中遇到的最多的算法.目前主流的算法有8种. 平均时间复杂度从高到低依次是: 冒泡排序(o(n2)),选择排序(o(n2)),插入排序(o(n2)),堆排序(o(nlogn)), ...

  6. CDOJ 1502 string(简单贪心)

    题目大意:原题链接 相邻两个字母如果不同,则可以结合为前一个字母,如ac可结合为a.现给定一个字符串,问结合后最短可以剩下多少个字符串 解体思路:简单贪心 一开始读题时,就联想到之前做过的一道题,从后 ...

  7. struts.xml 配置文件的主要元素

    1.package元素 作用: 在struts2的配置文件中引入了面向对象思想.分包管理,易于管理动作类,便于模块化开发动作类. 属性: name:包的名称.名称唯一. extends:一般情况下需要 ...

  8. linux上mysql访问:Access denied for user 'agtipay'@'iZm5ebiyb4f90ga9xiycgsZ' (using password: YES)

    公司的聚合支付测试环境出了一个问题(agtipay用户访问数据的时候出现如题错误),快搞死我两天时间(原谅技术不才),如题.首先明确一下问题: 1.访问拒绝,说明数据库连接这里有问题,数据库连接访问拒 ...

  9. Decker容器使用

    Docker 客户端 我们可以直接输入 docker 命令来查看到 Docker 客户端的所有命令选项 root@ranxf:/home/ranxf# docker Usage: docker COM ...

  10. oracle安装完成后目录中不论有没有tnsnames.ora和listener.ora文件 PLSQL都能连上的问题解决方法

    今天遇到这个问题了,发现listener.ora文件和tnsnames.ora文件在Net Work文件夹下没有,正常情况下安装完oracle或者是oracle Client是会有的,但是在Net M ...