• 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. Zookeeper简介及使用

    一.Zookeeper简介 1.zookeeper简介 动物管理员 Apache ZooKeeper致力于开发和维护开源服务器,实现高度可靠的分布式协调. 2.什么是ZooKeeper? ZooKee ...

  2. Windows10安装MySQL5.6.24

    1.解压安装包到指定目录如:E:\Java\mysql-5.6-24-win32 2.在E:\Java\mysql-5.6-24-win32目录下新建my.ini文件,内容如下 [mysqld] ba ...

  3. Linux时间管理涉及数据结构和传统低分辨率时钟的实现

    上篇文章大致描述了Linux时间管理的基本情况,看了一些大牛们的博客感觉自己写的内容很匮乏,但是没办法,只能通过这种方式提升自己……闲话不说,本节介绍下时间管理下重要的数据结构 设备相关数据结构 // ...

  4. 新手怎么读懂一个中型的Django项目

    [前言]中型的项目是比较多的APP,肯会涉及多数据表的操作.如果有人带那就最好了,自己要先了解基本的django框架(MTV ,ORM等)师傅可以给讲解一下框架怎么组织url.py,model.py, ...

  5. 怎样将Arranged_2压入General_Polygon_set_2中

    Thursday, March 14, 2013 How to Jam an Arrangement_2 into a General_polygon_set_2 I spent about thre ...

  6. cmd 运行jar文件

    将java工程打成jar包,但第三方jar包并没有包含在包中,当在命令行中运行jar包时,出现类找不到的异常, 在网上看到解决办法是将第三方jar包放到JDK的扩展类文件夹中(%JAVA_HOME%/ ...

  7. python学习笔记(二十)初识面向对象

    面向对象的编程的主要思想是把构成问题的各个事物分解成各个对象,建立对象的目的不是为了完成一个步骤,而是为了描述一个事物在解决问题的过程中经历的步骤和行为.对象作为程序的基本单位,将程序和数据封装其中, ...

  8. TraClus java版实现

           前一阵子我们部门接到了业务那边的一个需求.想通过用户的wifi数据计算出商场内用户最喜爱走的线路.其实说白了就是用户轨迹聚类.根据业务的需求,我们最终采用了traClus聚类算法.tra ...

  9. Oracle trigger 触发器

    触发器使用教程和命名规范 目  录触发器使用教程和命名规范 11,触发器简介 12,触发器示例 23,触发器语法和功能 34,例一:行级触发器之一 45,例二:行级触发器之二 46,例三:INSTEA ...

  10. yii2引入js和css

    assets/AppAsset.php public $css = [ 'css/site.css', 'css/font/css/font-awesome.min.css', 'css/doc.cs ...