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 folder containing the files that can be deployed on a web server hosting your project. This distribution folder would be built from your project files using various NPM packages and scripts. At the end of this exercise, you will be able to:
- Clean out a folder using the clean NPM module.
- Copy files from one folder to another
- Prepare a minified and concatenated css file from all the css files used in your project
- Prepare an uglified and concatenated JS file containing all the JS code used in your project
Cleaning up a Distribution Folder
- Install the rimraf npm module by typing the following at the prompt:
- Then, set up the following script:
Copying Fonts
- Your project uses font-awesome fonts. These need to be copied to the distribution folder. To help us do this, install the copyfiles NPM module globally as follows:
Remember to use sudo on mac and Linux.
- Then set up the following script:
Compressing and Minifying Images
- We use the imagemin-cli NPM module to help us to compress our images to reduce the size of the images being used in our project. Install the imagemin-cli module as follows:
Remember to use sudo on mac and Linux. NOTE: Some students have encountered issues with imagemin-cli not installing its plugins due to issues with global permissions on Mac. In that case try
- Then set up the following script:
Preparing the Distribution Folder
- Open .gitignore and update it as follows. We do not want the dist folder to be checked into the git repository.
- Then, install the usemin-cli, cssmin, uglifyjs and htmlmin NPM packages as follows:
- Add the following two scripts to the package.json file:
- Open index.html and surround the css links inclusion code as follows:
- Do the same change in aboutus.html and contactus.html
- Similarly, open index.html and surround the js script inclusion code as follows:
- Do the same change in aboutus.html and contactus.html
- To build the distribution folder, you can type the following at the prompt:
- This will build the dist folder containing the files that are a self-contained version of your project. You can now copy the contents of this folder to a web server that hosts your website.
- After verifying that the dist folder is built correctly, you can now do a git commit with the message "NPM Scripts Part 2"
Conclusions
In this exercise, you learnt the various steps to build the project for deployment using NPM scripts.
Additional Resources
NPM Modules
NPM Scripts 2 -- rimraf copyfiles imagemin usemin htmlmin uglifyjs的更多相关文章
- npm Scripts使用教程【译】
		Why npm Scripts? 原文发表于 2016.2.12,原文地址: https://css-tricks.com/why-npm-scripts/ 以下是访客Damon Bauer发布的一篇 ... 
- npm scripts + webpack 实践经验(React、Nodejs)
		最近用Webpack+npm scripts+Mongodb+Nodejs+React写了个后台项目,在用Webpack构建过程中遇到了许多坑,就写出来分享一下. 构建工具五花八门,想当年刚学会Gru ... 
- npm scripts 使用指南
		转载自:http://www.ruanyifeng.com/blog/2016/10/npm_scripts.html Node 开发离不开 npm,而脚本功能是 npm 最强大.最常用的功能之一. ... 
- 二、npm scripts
		一.执行原理 安装npm 包,会将其package.json bin 字段添加到node_modules bin 里面,创建对应的.cmd文件,因此: 例如: "scripts": ... 
- [NPM] Make npm scripts cross-environment friendly
		Unfortunately not all shell commands work across various environments. Two main techniques to suppor ... 
- npm scripts 助力前端开发,实时刷新浏览器
		用browser-sync或者lite-server来监控文件的改变,当文件改变时,就自动刷新浏览器. 用node-sass来实时编译scss文件. 用parallelshell来异步执行npm sc ... 
- windows下npm scripts不能执行的问题
		最近在学webpack为了方便把运行脚本写入package.json文件中,如下: "scripts": { "start": "webpack-de ... 
- 5.npm scripts 使用指南
		简单介绍 scripts里面的 "start": "node app" npm run start 相当于 node app { "name" ... 
- npm scripts 脚本基础指南
		什么是npm脚本? npm 允许在package.json文件里面,使用scripts字段定义脚本命令. 初始化package.json -> npm init -> 经历一系列的问答即可 ... 
随机推荐
- libtorch 哪些函数比较常用?
			libtorch 加载 pytorch 模块进行预测示例 void mat2tensor(const char * path, torch::Tensor &output) { //读取图片 ... 
- Spark应用日志级别设置
			一. 日志效率原因 开发时,控制台输出一大堆日志信息,严重影响查看日志效率. 从控制台输出日志我们可以看出,应用程序是默认加载Spark-core包下面的log4j-defaults.proper ... 
- UVA10026:Shoemaker's Problem(贪心)
			题目链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68990#problem/K 题目需求:鞋匠有n个任务,第i个任务要花费ti ... 
- JDB调试代码 20165324 何春江
			Java书本程序调试: 课上程序调试 
- 在MFC中使用一个单独的类实现数据在各个类之间的传递
			第一步:使用VS2010创建一个基于MFC的单文档程序,然后 编译 运行 确定没有问题. 第二步:添加一个名叫CGszCommonData 类. 第三步:在应用程序类的头文件里 添加#includ ... 
- 接口返回值结果转换成JSON
			接口返回值结果转换成JSON,具体的方法如下: public static String GetJsonValue(String result,int index,String key){ int i ... 
- javascript 类型 内存
			ecmscript中包含两种类型 基本类型值 引用类型值(对象) 按值传递和按引用传递 function test ($num) { //按值传递,JavaScript中没有按引用 ... 
- 【转】Google的2012论文
			转自:http://www.sigvc.org/bbs/thread-1152-1-1.html Google的论文一直是业界的风向标,尤其在机器学习.分布式系统.网络等方面很多创新性的成果都是由他们 ... 
- httpfs的使用
			在项目中使用到hdfs作为存储,为了在不同的节点加载hdfs上的数据,我们使用nfsv3服务,在客户端使用 root来mount hdfs上的数据到本地,然后把本地的数据发到hdfs上,因为这个我们的 ... 
- web前端基础——初识HTML
			1 HTML概念 HTML(Hypertext Markup Language)即超文本标记语言,是网页的描述语言.它其实是一种描述网页的标准,它通过给需要描述的内容加上标签,浏览器按照HTML语言的 ... 
