gulpfile.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const gulp = require('gulp'),
  2. useref = require('gulp-useref'),
  3. gulpif = require('gulp-if'),
  4. uglify = require('gulp-uglify'),
  5. cleanCSS = require('gulp-clean-css'),
  6. rename = require("gulp-rename"),
  7. concat = require("gulp-concat"),
  8. browserSync = require('browser-sync').create();
  9. gulp.task('copy', async function() {
  10. gulp.src('./node_modules/bootstrap/dist/css/bootstrap.css')
  11. .pipe(gulp.dest('./css/'));
  12. gulp.src('./node_modules/bootstrap/dist/js/bootstrap.js')
  13. .pipe(gulp.dest('./js/'));
  14. gulp.src('./node_modules/jquery/dist/jquery.min.js')
  15. .pipe(gulp.dest('./js/'));
  16. console.log("Files copied from npm packages");
  17. });
  18. gulp.task('build', async function() {
  19. gulp.src('./css/bootstrap.css','./css/style.css')
  20. .pipe(concat('style.min.css'))
  21. .pipe(gulp.dest('./app/css/'));
  22. gulp.src('index.html')
  23. .pipe(useref())
  24. .pipe(gulpif('*.js', uglify()))
  25. .pipe(gulpif('*.css', cleanCSS({level: {1: {specialComments: 0}}})))
  26. .pipe(gulp.dest('./app/'));
  27. console.log("Assets packaged for app/");
  28. });
  29. function run() {
  30. browserSync.init({
  31. server: {
  32. baseDir: "./",
  33. index: "/index.html"
  34. }
  35. });
  36. gulp.watch('./css/**/*.css').on('change', browserSync.reload);;
  37. gulp.watch('./*.html').on('change',browserSync.reload);
  38. gulp.watch('./js/**/*.js').on('change', browserSync.reload);
  39. }
  40. exports.run = run;