Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var browserify = require('browserify'),
  2.     tsify = require('tsify'),
  3.     gulp = require('gulp'),
  4.     sass = require('gulp-sass'),
  5.     ts = require('gulp-typescript'),
  6.     autoprefixer = require('gulp-autoprefixer'),
  7.     source = require('vinyl-source-stream'),
  8.     buffer = require('vinyl-buffer'),
  9.     tslint = require('gulp-tslint'),
  10.     uglify = require('gulp-uglify'),
  11.     browserSync = require('browser-sync');
  12.  
  13. var entryPoint = './src/scripts/main.ts',
  14.     browserDir = './',
  15.     sassWatchPath = './src/styles/**/*.scss',
  16.     jsWatchPath = './src/scripts/**/*.ts',
  17.     htmlWatchPath = './**/*.html';
  18.  
  19.  
  20. gulp.task('lint:ts', function() {
  21.     return gulp.src('./src/scripts/**/*.ts')
  22.         .pipe(tslint({
  23.             formatter: "verbose"
  24.         }))
  25.         .pipe(tslint.report())
  26. });
  27.  
  28. gulp.task('compile:ts',["lint:ts"], function () {  
  29.     return browserify()
  30.         .add(entryPoint)
  31.         .plugin(tsify)
  32.         .bundle()
  33.         .on('error', function (error) { console.error(error.toString()); })
  34.         .pipe(source('bundle.js'))
  35.         .pipe(buffer())
  36.         .pipe(uglify())
  37.         .pipe(gulp.dest('./build/js'));
  38. });
  39.  
  40. gulp.task('browser-sync', function () {
  41.     const config = {
  42.         server: {baseDir: browserDir}
  43.     };
  44.  
  45.     return browserSync(config);
  46. });
  47.  
  48. gulp.task('sass', function () {
  49.   return gulp.src(sassWatchPath)
  50.     .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
  51.     .pipe(autoprefixer({
  52.         browsers: ['last 2 versions']
  53.     }))
  54.     .pipe(gulp.dest('./build/css'))
  55.     .pipe(browserSync.reload({stream: true}));
  56. });
  57.  
  58. gulp.task('watch', function () {
  59.     gulp.watch(jsWatchPath, ['compile:ts']);
  60.     gulp.watch(sassWatchPath, ['sass']);
  61.     gulp.watch(htmlWatchPath, function () {
  62.         return gulp.src('')
  63.             .pipe(browserSync.reload({stream: true}))
  64.     });
  65. });
  66.  
  67. gulp.task('run', ['compile:ts', 'sass', 'watch','browser-sync']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement