Skip to content

Instantly share code, notes, and snippets.

@weihanchen
Created October 25, 2016 00:32
Show Gist options
  • Save weihanchen/467d2e9920f1db2aa1fcb1c2ef640eae to your computer and use it in GitHub Desktop.
Save weihanchen/467d2e9920f1db2aa1fcb1c2ef640eae to your computer and use it in GitHub Desktop.
gulp
var gulp = require('gulp' ),
minifycss = require( 'gulp-minify-css'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
cache = require('gulp-cache'),
livereload = require( 'gulp-livereload'),
connect = require('gulp-connect'),
ngAnnotate = require( 'gulp-ng-annotate'),
sourcemaps = require( 'gulp-sourcemaps')
gulp.task('buildJs', function () {
return gulp.src([ 'js/controllers/*.js', 'js/directive/*.js' , 'js/filters/*.js', 'js/services/*.js' ])
.pipe(ngAnnotate()) //使用ngAnnotate轉換為Inline Array Annotation,防止注入錯誤
.pipe(concat( 'rewardRecord.min.js'))
.pipe(uglify({
mangle: true
}))
.pipe(gulp.dest( './dist/')); //輸出目錄
});
gulp.task('buildCss', function () {
return gulp.src([ 'css/*.css'])
.pipe(sourcemaps.init())
.pipe(concat( 'rewardRecord.min.css'))
.pipe(minifycss()) //最小化css
.pipe(sourcemaps.write())
.pipe(gulp.dest( './dist/')); //輸出目錄
});
gulp.task('server', function () {//建立臨時Server
connect.server({
livereload: true
});
});
gulp.task('html', function () {
gulp.src(['*.html', 'views/**/*.html', 'views/*.html'])
.pipe(connect.reload());
});
gulp.task('js', function () {
gulp.src(['js/controllers/*.js', 'js/directive/*.js', 'js/filters/*.js' , 'js/services/*.js'])
.pipe(connect.reload());
});
gulp.task('css', function () {
gulp.src(['css/*.css'])
.pipe(connect.reload());
});
gulp.task('language', function () {
gulp.src(['language/*.json'])
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch(['*.html', 'views/**/*.html', 'views/*.html'], ['html' ]);
gulp.watch(['js/controllers/*.js', 'js/directive/*.js', 'js/filters/*.js' , 'js/services/*.js'], ['js' ]);
gulp.watch(['language/*.json'], [ 'language']);
gulp.watch(['css/*.css'], [ 'css']);
});
gulp.task('default', ['buildJs', 'buildCss']);
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload');
npm install gulp -g
//將 gulp 安裝到本地端的專案內,並紀錄於 package.json 內的devDependencies 屬性。
npm install gulp --save-dev
gulp.task('jsMin', function () {
return gulp.src(['js/controllers/app.js', 'js/controllers/rewardRecord.js'])
.pipe(concat('dist/assets.js')).pipe(uglify({
mangle: true
})).pipe(gulp.dest('js'));
});
gulp.task('default', ['jsMin']);
gulp.task('server', function () {//建立臨時Server
connect.server({
livereload: true
});
});
gulp.task('watch', function () {//監看的檔案
gulp.watch('*', ['index']);
gulp.watch(['js/**/*.js'], ['js']);
gulp.watch(['views/**/*.html', 'views/*.html'], ['views']);
gulp.watch('css/*.css', ['css']);
gulp.watch('language/*.json', ['lang']);
});
gulp.task('default', ['server','watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment