Advertisement
Guest User

Untitled

a guest
May 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const gulp = require("gulp"),
  2.     source = require('vinyl-source-stream'),
  3.     buffer = require('vinyl-buffer'),
  4.     browserify = require('browserify'),
  5.     plumber = require('gulp-plumber'),
  6.     autoprefixer = require('gulp-autoprefixer'),
  7.     browserSync = require('browser-sync').create(),
  8.     uglify = require('gulp-uglify'),
  9.     sass = require('gulp-sass'),
  10.     notify = require('gulp-notify'),
  11.     babel = require('gulp-babel'),
  12.  
  13.  
  14.     paths = {
  15.         src: {
  16.             html: "./index.html",
  17.             js: "./src/js/**/*.js",
  18.             css: "./src/scss/**/*.scss",
  19.         },
  20.         dest: {
  21.             js: "./public/js/",
  22.             css: "./public/css/"
  23.         }
  24.  
  25.     },
  26.     showError = function (error) {
  27.         console.log(error.toString());
  28.         this.emit('end');
  29.     };
  30.  
  31.  
  32. function html() {
  33.     return gulp.src(paths.src.html)
  34.         .pipe(browserSync.stream());
  35. };
  36.  
  37. exports.html = html;
  38.  
  39. function css() {
  40.     return gulp.src(paths.src.css)
  41.         .pipe(sass().on('error', sass.logError))
  42.         .pipe(gulp.dest(paths.dest.css))
  43.         .pipe(browserSync.stream());
  44. };
  45. exports.css = css;
  46.  
  47. function js() {
  48.     var b = browserify({
  49.         entries: "./src/js/main.js",
  50.         debug: true
  51.     })
  52.  
  53.     return b
  54.  
  55.         .transform('babelify', {
  56.             presets: ["@babel/preset-env"],
  57.             sourceMaps: true
  58.         })
  59.         .bundle()
  60.         .pipe(plumber({
  61.             errorHandler: function (err) {
  62.                 notify.onError({
  63.                     title: "Gulp error in " + err.plugin,
  64.                     message: err.toString()
  65.                 })(err);
  66.             }
  67.         }))
  68.         .pipe(source('main.js'))
  69.         .pipe(buffer())
  70.         //.pipe(uglify())
  71.         .pipe(gulp.dest(paths.dest.js))
  72.         .pipe(browserSync.stream());
  73. };
  74. exports.js = js;
  75.  
  76. function jsprod() {
  77.     return gulp.src("./src/js/module360-prod.js")
  78.         .pipe(babel({
  79.             presets: ['@babel/env']
  80.         }))
  81.  
  82.         .pipe(plumber({
  83.             errorHandler: function (err) {
  84.                 notify.onError({
  85.                     title: "Gulp error in " + err.plugin,
  86.                     message: err.toString()
  87.                 })(err);
  88.             }
  89.         }))
  90.         //.pipe(uglify())
  91.         .pipe(gulp.dest(paths.dest.js));
  92.     //.pipe(browserSync.stream());
  93. }
  94. exports.jsprod = jsprod;
  95.  
  96.  
  97. function watch() {
  98.     gulp.watch(paths.src.js, js);
  99.     gulp.watch(paths.src.css, css);
  100.     gulp.watch(paths.src.html, html);
  101. }
  102. exports.watch = watch;
  103.  
  104. function serve() {
  105.     browserSync.init({
  106.         server: {
  107.             baseDir: "./"
  108.         }
  109.     });
  110. }
  111.  
  112. exports.serve = serve;
  113.  
  114. const dev = gulp.series(gulp.parallel(watch, serve), gulp.parallel(js, css, html));
  115.  
  116. exports.default = dev;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement