Created
May 23, 2018 01:38
-
-
Save richogreen/9511dca32d7f25dab2d81232a141fad4 to your computer and use it in GitHub Desktop.
Gulp setup for Drupal 8 (Acquia DevDesktop, SASS, ES6, Browser Sync)
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
var gulp = require('gulp'); | |
var browserSync = require('browser-sync'); | |
var sass = require('gulp-sass'); | |
var prefix = require('gulp-autoprefixer'); | |
var concat = require('gulp-concat'); | |
var babel = require('gulp-babel'); | |
var cp = require('child_process'); | |
/** | |
* Launch the Server | |
*/ | |
gulp.task('browser-sync', ['sass', 'scripts'], function() { | |
browserSync.init({ | |
open: 'external', | |
host: 'localhost', | |
proxy: "http://localhost:8083", | |
port: 8083 | |
}); | |
}); | |
/** | |
* @task sass | |
* Compile files from scss | |
*/ | |
gulp.task('sass', function () { | |
return gulp.src('src/scss/styles.scss') | |
.pipe(sass()) | |
.pipe(prefix(['last 3 versions', '> 1%', 'ie 8'], { cascade: true })) | |
.pipe(gulp.dest('assets/css')) | |
.pipe(browserSync.reload({stream:true})) | |
}); | |
/** | |
* @task scripts | |
* Compile files from js | |
*/ | |
gulp.task('scripts', function() { | |
return gulp.src(['src/js/*.js', '_js/custom.js']) | |
.pipe(babel({ | |
presets: ['es2015'] | |
})) | |
.pipe(concat('scripts.js')) | |
.pipe(gulp.dest('js')) | |
.pipe(browserSync.reload({stream:true})) | |
}); | |
/** | |
* @task clearcache | |
* Clear all caches | |
*/ | |
gulp.task('clearcache', function(done) { | |
return cp.spawn('drush', ['cache-rebuild'], {stdio: 'inherit'}) | |
.on('close', done); | |
}); | |
/** | |
* @task reload | |
* Refresh the page after clearing cache | |
*/ | |
gulp.task('reload', ['clearcache'], function () { | |
browserSync.reload(); | |
}); | |
/** | |
* @task watch | |
* Watch scss files for changes & recompile | |
* Clear cache when Drupal related files are changed | |
*/ | |
gulp.task('watch', function () { | |
gulp.watch(['src/scss/*.scss', 'src/scss/**/*.scss'], ['sass']); | |
gulp.watch(['src/js/*.js'], ['scripts']); | |
gulp.watch(['templates/*.html.twig', '**/*.yml'], ['reload']); | |
}); | |
/** | |
* Default task, running just `gulp` will | |
* compile Sass files, launch BrowserSync, watch files. | |
*/ | |
gulp.task('default', ['browser-sync', 'watch']); |
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
{ | |
"name": "myfi", | |
"version": "1.0.0", | |
"description": "", | |
"main": "gulpfile.js", | |
"devDependencies": { | |
"babel-preset-es2015": "^6.24.1", | |
"browser-sync": "^2.18.13", | |
"gulp": "^3.9.1", | |
"gulp-autoprefixer": "^4.0.0", | |
"gulp-babel": "^6.1.2", | |
"gulp-concat": "^2.6.1", | |
"gulp-sass": "^3.1.0", | |
"normalize.css": "^8.0.0" | |
}, | |
"scripts": { | |
"postinstall": "find node_modules/ -name '*.info' -type f -delete" | |
}, | |
"author": "rgreen <rg@ie.com.au>", | |
"license": "ISC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment