Skip to content

Instantly share code, notes, and snippets.

@guoxiangke
Created July 28, 2016 04:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guoxiangke/7f855d1322307c8e0c9a729be3f723ce to your computer and use it in GitHub Desktop.
Save guoxiangke/7f855d1322307c8e0c9a729be3f723ce to your computer and use it in GitHub Desktop.
drupal8-glup
var Promise = require('es6-promise').Promise;
var gulp = require('gulp');
var livereload = require('gulp-livereload')
var uglify = require('gulp-uglifyjs');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
// http://blog.andrewray.me/how-to-copy-only-changed-files-with-gulp/
var watch = require('gulp-watch');
// http://gulpjs.org/recipes/handling-the-delete-event-on-watch.html
var del = require('del');
var path = require('path');
var source = './backend',
destination = './public_html';
theme = 'custom/lovetheme'//?
gulp.task('copy-change', function() {
gulp.src(source + '/**/*', {base: source})
.pipe(watch(source, {base: source}))
.pipe(gulp.dest(destination));
});
// gulp.task('copy-folder', function() {
// gulp.src(source + '/**/*')
// .pipe(gulp.dest(destination));
// });
gulp.task('imagemin', function () {
return gulp.src(source + '/themes/'+theme+'/images/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(source + '/themes/'+theme+'/images'));
});
gulp.task('sass', function () {
gulp.src(source + '/themes/'+theme+'/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 7', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(sourcemaps.write('./public_html/'))
.pipe(gulp.dest(source + '/themes/'+theme+'/css'));
});
gulp.task('uglify', function() {
gulp.src(source + '/themes/'+theme+'/lib/*.js')
.pipe(uglify('main.js'))
.pipe(gulp.dest(source + '/themes/'+theme+'/js'))
});
gulp.task('watch', function(){
livereload.listen();
gulp.watch(source + '/**/*', ['copy-change']);
var watcher = gulp.watch(source + '/**/*');
watcher.on('change', function (event) {
if (event.type === 'deleted') {
var filePathFromSrc = path.relative(path.resolve('backend'), event.path);
var destFilePath = path.resolve('public_html', filePathFromSrc);
del.sync(destFilePath);
}
});
gulp.watch(source + '/themes/'+theme+'/sass/**/*.scss', ['sass']);
gulp.watch(source + '/themes/'+theme+'/lib/*.js', ['uglify']);
gulp.watch([source +'/themes/'+theme+'/css/style.css', source +'/themes/custom/'+theme+'/**/*.twig', source +'/themes/'+theme+'/js/*.js'], function (files){
livereload.changed(files)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment