Skip to content

Instantly share code, notes, and snippets.

@anonymousraft
Created May 20, 2020 09:11
Show Gist options
  • Select an option

  • Save anonymousraft/d309ca21d1eff0b0d6770f58f0d3f416 to your computer and use it in GitHub Desktop.

Select an option

Save anonymousraft/d309ca21d1eff0b0d6770f58f0d3f416 to your computer and use it in GitHub Desktop.
Gulp 4.0 Compatibility
'use strict';
const { watch, series, src, dest } = require( 'gulp' );
//css packages
const sass = require( 'gulp-sass' );
const autoprefixer = require( 'gulp-autoprefixer' );
//generic package
const sourcemaps = require( 'gulp-sourcemaps' );
const rename = require( 'gulp-rename' );
//js packages
const browserify = require( 'browserify' );
const babelify = require( 'babelify' );
const source = require( 'vinyl-source-stream' );
const buffer = require( 'vinyl-buffer' );
const uglify = require( 'gulp-uglify' );
const styleSRC = 'src/scss/style.scss';
const styleDIST = './dist/css/';
const styleWatch = 'src/scss/**/*.scss'
var jsSRC = 'src/js/script.js';
const jsDIST = './dist/js/';
const jsWatch = 'src/js/**/*.js';
const jsFILES = [jsSRC];
function style(){
return src( styleSRC )
.pipe( sourcemaps.init() )
.pipe( sass( {
errorLogToConsole: true,
outputStyle: 'compressed'
} ))
.on( 'error', console.error.bind( console ) )
.pipe( autoprefixer( {
overrideBrowserslist: ['last 2 versions'],
cascade: false
} ) )
.pipe( rename( { suffix:'.min' } ) )
.pipe( sourcemaps.write( './' ) )
.pipe( dest( styleDIST ) );
}
function js(){
var b = browserify({
entries: jsSRC,
debug: true
})
.transform("babelify", {presets: ["@babel/preset-env"]});
return b.bundle()
.pipe( source( 'script.js' ) )
.pipe( rename({ extname: '.min.js' }))
.pipe( buffer() )
.pipe( sourcemaps.init( { loadMaps:true } ))
.pipe( uglify() )
.pipe( sourcemaps.write( './' ) )
.pipe( dest( jsDIST ) );
}
exports.style = style;
exports.js = js;
exports.default = series(style,js);
exports.watch = series(style,js,function(){
watch( styleWatch, style );
watch( jsWatch, js );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment