category: gulp

JavaScript - Google Closure Compiler V.S. Gulp uglify

on 2015-08-15

JavaScript - Google Closure Compiler V.S. Gulp uglify

Intro

I have two choice

  1. Google Closure Compiler

  2. UglifyJs

Google Closure Compiler

Google Closure Compiler

Google Closure Compiler is a tool for minify and uglify js.

  • From Google

  • Java

  • Command Line

  • Slow

UglifyJs

mishoo/UglifyJS2

  • More option setting

  • Node.js

  • Command Line

  • Fast

Test

Google Closure Compiler

When i run command line, it used lot of cpu source.

Can feel it lock some seconds.

If compiler error,it can show error message.

UglifyJs

It’s so fast.

It can fix some small error when it compiler.

So i recommendation this tool.

Finally i use Gulp handle uglifyJs.

Read more

gulp.js - Concatenate File When Gulp Watch

on 2015-08-09

gulp.js - Concatenate File When Gulp Watch

package.json

{
  "name": "gulp",
  "version": "3.8.7",
  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-concat": "^2.6.0",
    "gulp-watch": "^4.3.4"
  }
}

gulpfile.js

var gulp = require('gulp'),
    watch = require('gulp-watch'),
    concat = require('gulp-concat');

var js;
gulp.task('concat', function (cb) {
    var options = {};
    watch('dev/*.js', options, function (e) {
        // console.log('e:'+JSON.stringify(e));
        // console.log('\n');
        console.log(new Date() + ' -- ' + e.history[0].replace(e.base, ''));
        js = e.history[0].replace(e.base, '');
        gulp.src(['util/util.js', 'util/mod.js', 'dev/' + js])
        .pipe(concat(js, {newLine: '\n'}))
        .pipe(gulp.dest('dist/'));
    });
});

What it mean?

watch something change in dev/*.js.

If js change, concatenate util/util.js, util/mod.js and current modify js.

New js name is current modify js.

Finally put new js in dist/.

How to use

Install

npm install --save-dev gulp

npm install . --save-dev

Use

gulp concat

Refer - gulp-watch

Refer - gulp-concat

Read more