Advertisement
ikamal7

gulpfile.js

Sep 23rd, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const gulp = require('gulp');
  2. const babel = require('gulp-babel');
  3. const vueify = require('vueify');
  4. const sourcemaps = require('gulp-sourcemaps');
  5. const rename = require('gulp-rename');
  6. const cleanCSS = require('gulp-clean-css');
  7. const sass = require('gulp-sass')(require('sass'));
  8. const autoprefixer = require('gulp-autoprefixer');
  9.  
  10. const srcPath = 'src'; // Change this to the actual path of your source files
  11. const destPath = 'dist'; // Change this to the destination path for compiled files
  12.  
  13. gulp.task('js', () => {
  14.     return gulp.src([`${srcPath}/**/*.js`, `${srcPath}/**/*.vue`])
  15.       .pipe(sourcemaps.init())
  16.       .pipe(babel({ presets: ['@babel/preset-env'] }))
  17.       .pipe(vueify())
  18.       .pipe(sourcemaps.write('.'))
  19.       .pipe(gulp.dest(destPath));
  20.   });
  21.  
  22. // CSS Compilation (Sass, SCSS, etc.)
  23. gulp.task('css', () => {
  24.   return gulp.src(`${srcPath}/**/*.scss`)
  25.     .pipe(sourcemaps.init())
  26.     .pipe(sass())
  27.     .pipe(autoprefixer())
  28.     .pipe(rename({ suffix: '.min' }))
  29.     .pipe(cleanCSS())
  30.     .pipe(sourcemaps.write('.'))
  31.     .pipe(gulp.dest(destPath));
  32. });
  33.  
  34. // Watch for changes and run tasks
  35. gulp.task('watch', () => {
  36.   gulp.watch(`${srcPath}/**/*.js`, gulp.series('js'));
  37. //   gulp.watch(`${srcPath}/**/*.vue`, gulp.series('vue'));
  38.   gulp.watch(`${srcPath}/**/*.scss`, gulp.series('css'));
  39. });
  40.  
  41. // Define the default task
  42. gulp.task('default', gulp.parallel('js','css', 'watch'));
  43.  
  44. // Define a task to build for production (minification)
  45. gulp.task('build', gulp.parallel('js', 'css'));
  46.  
  47. // Clean the destination folder
  48. gulp.task('clean', () => {
  49.   return gulp.src(destPath, { read: false, allowEmpty: true })
  50.     .pipe(clean());
  51. });
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement