GithubHelp home page GithubHelp logo

notes's People

Contributors

tonghelin avatar

Watchers

 avatar

notes's Issues

20180428--【前端工程化】-- gulp -- Json

前端自动化构建工具gulp的使用记录

记录于20180428--Json

达到目标

  • 编译代码
  • 合并代码
  • 压缩代码
  • 压缩图片

开始使用

  1. 全局安装gulp模块
    npm install -g gulp
  2. 项目安装gulp
    npm install gulp --save
  3. 新建gulpfile.js 文件
    在项目更目录下新建gulpfile.js 文件

常用方法

* gulp.task    --  定义任务

gulp.task("任务名",function(){
//要执行的任务
});
* gulp.src -- 找到需要执行任务的文件
gulp.task("任务名",function(){
gulp.src("文件路径")
.pipe(gulp.dest('dist/'));
});
* gulp.dest -- 执行任务的文件的去处
gulp.task("任务名",function(){
gulp.src("文件路径")
.pipe(gulp.dest('dist/'));
});
* gulp.watch -- 观察文件是否发生变化

几个例子

  • 倒入模块
    var uglify = require("gulp-uglify");
  • 定义任务

    gulp.task("minify",function(){
    gulp.src("src/js/*.js")
    .pipe(uglify())
    .pipe(gulp.dest("dist"))
    })

几个模块

图片压缩模块--- gulp-imagemin
代码压缩模块--- gulp-uglify
代码合并模块--- gulp-concat

合并代码

var concat = require('gulp-concat');
var uglify = require('gulp-gulify');
gulp.task("name",function(){
gulp.src('src/js/*.js') //来源
.pipe(concat("main.js")) //合并
.pipe(uglify()) //压缩
.pipe(gulp.dest('dist/js')) //输出
})

执行多个任务

gulp.task('default',['任务01','任务02','任务03','任务04'])

监听文件变化

gulp.watch('需要监听的文件的路径',['文件变化需要执行的任务']);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.