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 -> 经历一系列的问答即可 ...
随机推荐
- 吉哥系列故事——完美队形II---hdu4513(最长回文子串manacher)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4513 题意比最长回文串就多了一个前面的人要比后面的人低这个条件,所以在p[i]++的时候判断一下s[i ...
- 转载--菜鸟Linux上使用Github
1.安装Git:Ctrl + Alt + T使用终端:使用命令 sudo apt-get install git 2.创建GitHub帐号:登陆git主页: https://github.com/,自 ...
- ObjectDetection中的一些名词中英文对照
mAP:mean Average Precision,平均精确度 recall rate:召回率 Loss Function Anchro
- Mybatis在Maven项目中使用
Mybatis概览 ORM是什么? ORM是Object Realtion Mapping的缩写,顾名思义,即对象关系映射. ORM是一种以面向对象的方式来进行数据库操作的技术.Web开发中常用的语言 ...
- html知识代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- node.js---sails项目开发
http://sailsdoc.swift.ren/ 这里有 sails中文文档 node.js---sails项目开发(1)安装,启动sails node.js---sails项目开发(2)安装测试 ...
- mysql 下的命令
1.查看mysql日志vim /var/log/mysqld.log
- table添加横向滚动条
<div style="width:1000px; height:200px; overflow:scroll;"> <table border=" r ...
- visual studio NuGet
http://www.cnblogs.com/dudu/archive/2011/07/15/nuget.html 首先打开程序包管理器控制台:工具→Nuget程序包管理器→程序包管理器控制台 Ins ...
- Delphi APP 開發入門(九)拍照與分享
Delphi APP 開發入門(九)拍照與分享 分享: Share on facebookShare on twitterShare on google_plusone_share 閲讀次數:30 ...