• 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. HDFS分布式集群安装

    HDFS集群安装: 1.准备工作 虚拟机(电脑8G内存 磁盘500GB) 3台 linux系统(1台namenode 2台datanode) (1)关闭防火墙 firewall-cmd --state ...

  2. POJ1330Nearest Common Ancestors最近公共祖先LCA问题

    用的离线算法Tarjan 该算法的详细解释请戳 http://www.cnblogs.com/Findxiaoxun/p/3428516.html 做这个题的时候,直接把1470的代码copy过来,改 ...

  3. Python中的编码与解码(转)

    Python中的字符编码与解码困扰了我很久了,一直没有认真整理过,这次下静下心来整理了一下我对方面知识的理解. 文章中对有些知识没有做深入的探讨,一是我自己也没有去深入的了解,例如各种编码方案的实现方 ...

  4. Python性能优化(转)

    分成两部分:代码优化和工具优化 原文:http://my.oschina.net/xianggao/blog/102600 阅读 Zen of Python,在Python解析器中输入 import ...

  5. K近邻python

    有一个带标签的数据集X,标签为y.我们想通过这个数据集预测目标点x0的所属类别. K近邻算法是指在X的特征空间中,把x0放进去,然后找到距离x0最近的K个点.通过这K个点所属类别,一般根据少数服从多数 ...

  6. 前端 javascript 变量

    变量: python: name = 'alex' JavaScript: name = 'alex' # 全局变量 声明var var name = 'eric' # 局部变量 写全局变量基本好少J ...

  7. java-mybaits-00402-Mapper-动态sql-if、where、foreach、sql片段

    1.动态sql(重点) 通过mybatis提供的各种标签方法实现动态拼接sql. 什么是动态sql mybatis核心 对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接.组装.   ...

  8. request.getInputStream() 流只能读取一次问题

    问题: 一次开发过程中同事在 sptring interceptor 中获取 request body 中值,以对数据的校验和预处理等操作 .导致之后spring 在读取request body 值做 ...

  9. OOM问题分析

    一.背景 在实际的开发中,性能问题的分析一直是运维团队的痛点,无论是缓慢内存溢出还是迅速的内存爆炸,对系统和业务的破坏都是快速而巨大的,此贴分享下简单的分析内存问题的经验. 二.相关名词 分代:根据对 ...

  10. SpringBoot简介及第一个应用

    一.Spring时代变换 1. Spring1.x 时代 Spring初代都是通过xml文件配置bean,随着项目的不断扩大,繁琐的xml配置,混乱的依赖关系,难用的bean装配方式,由此衍生了spr ...