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 -> 经历一系列的问答即可 ...
随机推荐
- UVA11426 GCD - Extreme (II)---欧拉函数的运用
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Linux IPC之管道通信
2017-04-07 管道通信在linux中使用较为频繁的进程通信机制.基于unix一切皆文件的传统,管道也是一种文件.所以可以使用一般的VFS接口对管道进行读写操作,如read.write.具体管道 ...
- Python并行编程(十一):基于进程的并行
1.基本概念 多进程主要用multiprocessing和mpi4py这两个模块. multiprocessing是Python标准库中的模块,实现了共享内存机制,可以让运行在不同处理器核心的进程能读 ...
- 简单的SQL注入学习
引贴: http://blog.163.com/lucia_gagaga/blog/static/26476801920168184648754/ 首先需要编写一个php页面,讲php页面放入/opt ...
- lamp环境的搭建和安装
最近,部门有些系统需要迁移到新的机器上,因此需要在新的机器上安装lamp和lnmp的环境,因此在这里总结一下: 一. 安装lamp环境的步骤: (1).因为是新的机器,因此需要安装gcc的各种环境: ...
- DataGird 相关
DataGird控件 DataGirdView 控件 DataGird类 他们之间是什么关系??????? DataGridView 控件是替换 DataGrid 控件的新控 ...
- python阳历转阴历,阴历转阳历
#!/usr/bin/env python # coding:utf8 # author:Z time:2019/1/16 import sxtwl # 日历中文索引 ymc = [u"十一 ...
- 斐迅面试记录—SSL和TLS的区别
SSL 是洋文“Secure Sockets Layer”的缩写,中文叫做“安全套接层”.它是在上世纪90年代中期,由网景公司设计的.(顺便插一句,网景公司不光发明了 SSL,还发明了很多 Web 的 ...
- split_lzo_lib.sh
split_lzo_lib.sh #!/bin/sh#输入文件名filename=$1#分割文件大小filesize=4096#输出库文件名libname="lib"$(echo ...
- 【android】通过leakCanary找出程序内存泄露点
背景 内存泄露是咱新手比较头痛的问题,因为它不像崩溃,在开发环境可以根据提示的错误信息排查问题. 你都不知道咱的app是否哪个犄角旮旯藏着一个吞噬内存的黑洞. 排查android 内存泄露比较底层高端 ...