Created
March 20, 2016 20:03
-
-
Save kikill95/18d5d8a5ec323ed9b1c0 to your computer and use it in GitHub Desktop.
browserify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var gulp = require('gulp'), | |
| concat = require('gulp-concat'), | |
| ngAnnotate = require('gulp-ng-annotate'), | |
| uglify = require('gulp-uglify'), | |
| autoprefixer = require('gulp-autoprefixer'), | |
| sass = require('gulp-sass'), | |
| minifyCss = require('gulp-minify-css'), | |
| del = require('del'), | |
| imagemin = require('gulp-imagemin'), | |
| sourcemaps = require('gulp-sourcemaps'), | |
| babel = require('gulp-babel'), | |
| browserSync = require('browser-sync').create(), | |
| util = require('gulp-util'); | |
| gulp.task('default', ['clean'], function() { | |
| gulp.start('sass', 'images', 'scripts'); | |
| }); | |
| gulp.task('clean', function () { | |
| del(['css', 'js', 'images']); | |
| }); | |
| gulp.task('sass', function () { | |
| return gulp.src('web-src/scss/*.scss') | |
| .pipe(sourcemaps.init('')) | |
| .pipe(sass().on('error', sass.logError)) | |
| .on('error', browserifyHandler) | |
| .pipe(autoprefixer()) | |
| .pipe(minifyCss({ | |
| keepSpecialComments: 0 | |
| })) | |
| .pipe(sourcemaps.write('')) | |
| .pipe(gulp.dest('css')) | |
| .pipe(browserSync.stream()); | |
| }); | |
| gulp.task('images', function () { | |
| return gulp.src(['web-src/images/*']) | |
| .pipe(imagemin({ | |
| progressive: true, | |
| interlaced: true | |
| })) | |
| .pipe(gulp.dest('images/')) | |
| .pipe(browserSync.stream()); | |
| }); | |
| gulp.task('scripts', function() { | |
| return gulp.src(['modules/**/*.js', 'modules/**/js/*.js']) | |
| .pipe(sourcemaps.init()) | |
| .pipe(babel()) | |
| .on('error', browserifyHandler) | |
| .pipe(ngAnnotate()) | |
| .on('error', browserifyHandler) | |
| .pipe(concat('main.js')) | |
| .pipe(uglify()) | |
| .pipe(sourcemaps.write(".")) | |
| .pipe(gulp.dest('js/')) | |
| .pipe(browserSync.stream()); | |
| }); | |
| gulp.task('serve', function () { | |
| browserSync.init({ | |
| scriptPath: function (path, port, options) { | |
| return "/browser-sync/browser-sync-client.js"; | |
| }, | |
| socket: { | |
| domain: 'localhost:3000' | |
| }, | |
| server: { | |
| baseDir: "./" | |
| }, | |
| notify: false | |
| }); | |
| gulp.watch('web-src/scss/*.scss', ['sass']); | |
| gulp.watch('web-src/images/*', ['images']); | |
| gulp.watch(['modules/**/*.js', 'modules/**/js/*.js'], ['scripts']); | |
| gulp.watch(['index.html', 'modules/**/**/*.html']).on('change', browserSync.reload); | |
| }); | |
| function browserifyHandler(err) { | |
| util.log(util.colors.red('Error: ' + err.message)); | |
| this.end(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment