Last active
October 10, 2020 22:18
-
-
Save Rowadz/1444c28fcdd96c34e0fa33211d0373de to your computer and use it in GitHub Desktop.
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
const { series, parallel, src, dest } = require('gulp') | |
const { sync } = require('glob') | |
const sass = require('gulp-sass') | |
const { join } = require('path') | |
const cleanCSS = require('gulp-clean-css') | |
const babel = require('gulp-babel') | |
const uglify = require('gulp-uglify') | |
sass.compiler = require('node-sass') | |
const path = join(__dirname, 'src') | |
const compileSCSS = () => { | |
return src(sync(join(path, 'scss', '**/*.scss'))) | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(dest(join(path, 'dist'))) | |
} | |
const compileJS = () => { | |
// compiling all js (even nested) code from the `src/js` | |
return src(sync(join(path, 'js', '**/*.js'))) | |
.pipe( | |
babel({ | |
presets: ['@babel/env'], | |
}) | |
) | |
.pipe(dest(join(path, 'dist'))) | |
} | |
const minifyCSS = () => { | |
return src(sync(join(path, 'dist', '**/*.css'))) | |
.pipe(cleanCSS()) | |
.pipe(dest(join(path, 'dist'))) | |
} | |
const minifyJS = () => { | |
// minfy all the js (even nested ones) files inside `src/dist/` | |
return src(sync(join(path, 'dist', '**/*.js'))) | |
.pipe(uglify()) | |
.pipe(dest(join(path, 'dist'))) | |
} | |
// we are calling `compileJS` & `compileSCSS` in parallel and wating | |
// for them both to finish, then after that we are calling | |
// `minifyCSS` & `minifyJS` in the same way. cool right? | |
exports.default = series( | |
parallel(compileJS, compileSCSS), | |
parallel(minifyCSS, minifyJS) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment