gulp快速搭建web项目
2017-01-08 17:07
204 查看
前言:首先需要安装nodejs。全局安装gulp:npm install -g gulp
1、初始化项目:创建项目文件夹,然后在项目下npm init
2、使用gulp构建一个普通web项目,基本需要这些库(库有很多,自行选择),见代码1。
代码1:
3、在项目根目录创建gulpfile.js文件,基本套路如代码2
代码2:
gulp.src中的路径要根据实际情况。
4、在命令行运行gulp即可开始开发项目了。
1、初始化项目:创建项目文件夹,然后在项目下npm init
2、使用gulp构建一个普通web项目,基本需要这些库(库有很多,自行选择),见代码1。
代码1:
npm install --save-dev gulp del jshint gulp-rename gulp-concat gulp-jshint gulp-uglify gulp-connect gulp-imagemin gulp-minify-css gulp-minify-html gulp-processhtml gulp-autoprefixer
3、在项目根目录创建gulpfile.js文件,基本套路如代码2
代码2:
var gulp = require('gulp'), del = require('del'), rename = require('gulp-rename'), concat = require('gulp-concat'), jshint = require('gulp-jshint'), uglify = require('gulp-uglify'), connect = require('gulp-connect'), imagemin = require('gulp-imagemin'), minifycss = require('gulp-minify-css'), minifyhtml = require('gulp-minify-html'), processhtml = require('gulp-processhtml'), autoprefixer = require('gulp-autoprefixer'); gulp.task('server', function(){ connect.server({ root:['./'], port: 7003, livereload: true }); }); gulp.task('copy', function(){ gulp.src('*.json') .pipe(gulp.dest('dev')) .pipe(connect.reload()) }); gulp.task('html', function(){ gulp.src('*.html') .pipe(gulp.dest('dev')) .pipe(connect.reload()); }); gulp.task('images', function(){ gulp.src('img/*') .pipe(imagemin()) .pipe(gulp.dest('dev/img')) }); gulp.task('scripts', function () { gulp.src('js/*.js') .pipe(jshint()) .pipe(gulp.dest('dev/js')) .pipe(connect.reload()) }); gulp.task('watch', function () { // body... gulp.watch(['*.html'], ['html']); gulp.watch(['js/*.js'], ['scripts']); }); gulp.task('dist', function(){ gulp.src('dev/*.html') .pipe(processhtml()) .pipe(minifyhtml()) .pipe(gulp.dest('dist')); gulp.src('dev/js/*.js') .pipe(concat('app.min.js')) .pipe(uglify()) .pipe(gulp.dest('dist')); gulp.src('dev/img/*') .pipe(gulp.dest('dist/img')); }); gulp.task('default', ['server', 'html','images', 'scripts', 'copy', 'watch']);
gulp.src中的路径要根据实际情况。
4、在命令行运行gulp即可开始开发项目了。
相关文章推荐
- react+webpack快速搭建web项目
- 1.SpringBoot之Helloword 快速搭建一个web项目
- 用maven快速搭建spring mvc的web项目(配置到jackson 和 任务调度)
- 【SpringBoot探索一】SpringBoot快速搭建基础web项目
- 快速搭建gulp项目实战
- SpringBoot之1分钟快速搭建Web项目(一)
- vue2.x+webpack快速搭建前端项目框架详解
- Spring-Boot快速搭建web项目详细总结
- TWaver html5 + NodeJS + express + websocket.io + redis 快速搭建项目(二)
- React + webpack 快速搭建项目
- Spring Boot(二):快速搭建web项目或微服务
- 基于express框架快速搭建web项目
- gulp + webpack 搭建项目环境
- [置顶] WEB开发----Spring Boot项目快速搭建
- 1.SpringBoot之Helloword 快速搭建一个web项目
- 快速搭建基于Maven的通用Web项目(Spring-Mybatis-JSF-Jersey-Boostrap)
- TWaver html5 + NodeJS + express + websocket.io + redis 快速搭建项目(三)
- 通过Spring Boot + Mybatis + Redis快速搭建现代化Web项目
- TWaver html5 + NodeJS + express + websocket.io + redis 快速搭建项目(一)
- Sendmail+Openwebmail 精简快速搭建