Created
March 21, 2019 13:46
-
-
Save Magnacarter/5b130a05c489814d6c8fa92b0d4b9ee7 to your computer and use it in GitHub Desktop.
Gulp file with auto broswer refresh and auto-prefix
This file contains 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
"use strict"; | |
var gulp = require( 'gulp' ), | |
maps = require( 'gulp-sourcemaps' ), | |
autoprefixer = require( 'gulp-autoprefixer' ), | |
concat = require( 'gulp-concat' ), | |
uglify = require( 'gulp-uglify' ), | |
rename = require( 'gulp-rename' ), | |
sass = require( 'gulp-sass' ), | |
cleanCSS = require( 'gulp-clean-css' ), | |
del = require( 'del' ), | |
browserSync = require( 'browser-sync' ); | |
var path = { | |
SCSS_ADMIN : './scss/main.scss', | |
CSS_DIR : './css', | |
JS_DIR : './js', | |
JS_FILES : [ './js/admin-script.js', './js/select2.min.js' ], | |
CSS_FILES : [ './css/select2.min.css', './css/unsemantic-grid-responsive.css', './css/admin.css' ] | |
}; | |
/** | |
* Admin scripts | |
*/ | |
gulp.task( 'concatAdminScripts', function() { | |
return gulp.src( path.JS_FILES ) | |
.pipe( maps.init() ) | |
.pipe( concat( 'admin-app.js' ) ) | |
.pipe( maps.write( './' ) ) | |
.pipe( gulp.dest( path.JS_DIR ) ); | |
}); | |
/** | |
* Public scripts | |
*/ | |
gulp.task( 'concatScripts', function() { | |
return gulp.src( path.JS_FILES ) | |
.pipe( maps.init() ) | |
.pipe( concat( 'app.js' ) ) | |
.pipe( maps.write( './' ) ) | |
.pipe( gulp.dest( path.JS_DIR ) ); | |
}); | |
/** | |
* Admin sass | |
*/ | |
gulp.task( 'compileAdminSass', function() { | |
return gulp.src( path.SCSS_ADMIN ) | |
.pipe( maps.init() ) | |
.pipe( sass().on( 'error', sass.logError ) ) | |
.pipe( autoprefixer( { browsers: ["> 0%"] } ) ) | |
.pipe( rename( 'admin.css' ) ) | |
.pipe( maps.write('./') ) | |
.pipe( gulp.dest( path.CSS_DIR ) ) | |
}); | |
/** | |
* Admin css | |
*/ | |
gulp.task( 'concatAdminCSS', [ 'compileAdminSass' ], function() { | |
return gulp.src( path.CSS_FILES ) | |
.pipe( cleanCSS( { compatibility: 'ie8' } ) ) | |
.pipe( concat( 'peta_placement_style.css' ) ) | |
.pipe( gulp.dest( path.CSS_DIR ) ); | |
}); | |
/** | |
* Public sass | |
*/ | |
// gulp.task( 'compileSass', function() { | |
// return gulp.src( path.SCSS_PUB ) | |
// .pipe( maps.init() ) | |
// .pipe( sass().on( 'error', sass.logError ) ) | |
// .pipe( autoprefixer( { browsers: ["> 0%"] } ) ) | |
// .pipe( rename( 'pub.css' ) ) | |
// .pipe( maps.write() ) | |
// .pipe( gulp.dest( path.CSS_DIR ) ) | |
// }); | |
/** | |
* Public css | |
*/ | |
// gulp.task( 'concatCSS', [ 'compileSass' ], function() { | |
// return gulp.src( path.CSS_FILES ) | |
// .pipe( cleanCSS( { compatibility: 'ie8' } ) ) | |
// .pipe( concat( 'pub-styles.css' ) ) | |
// .pipe( gulp.dest( path.CSS_DIR ) ); | |
// }); | |
//gulp.task( 'cssWatch', [ 'concatCSS' ], browserSync.reload ); | |
gulp.task( 'jsWatch', [ 'concatScripts' ], browserSync.reload ); | |
gulp.task( 'cssAdminWatch', [ 'concatAdminCSS' ], browserSync.reload ); | |
gulp.task( 'jsAdminWatch', [ 'concatAdminScripts' ], browserSync.reload ); | |
gulp.task( 'watchFiles', function() { | |
browserSync({ | |
proxy: { | |
target: 'http://plugindev.test/' | |
} | |
}); | |
//gulp.watch([ './scss/**/*.scss' ], [ 'cssWatch' ]); | |
gulp.watch( './js/pub-script.js', [ 'jsWatch' ]); | |
gulp.watch([ './scss/**/*.scss' ], [ 'cssAdminWatch' ]); | |
gulp.watch( './js/admin-script.js', [ 'jsAdminWatch' ]); | |
}); | |
gulp.task( 'serve', [ 'watchFiles' ] ); | |
gulp.task( 'default', [ 'serve' ], function() { | |
console.log( 'Welcome to the Placement Plugin Gulp task runner!' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment