Skip to content

Instantly share code, notes, and snippets.

@piotrpog
Created February 18, 2019 01:14
Show Gist options
  • Save piotrpog/a7e56ea2713ea5d0fab451c3e282ecfd to your computer and use it in GitHub Desktop.
Save piotrpog/a7e56ea2713ea5d0fab451c3e282ecfd to your computer and use it in GitHub Desktop.
Craft Cms Gulpfile
var gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
const notifier = require('node-notifier');
gulp.task('dev', ['sass:development', 'watch:development', 'browser-sync']);
gulp.task('default', ['dev']);
gulp.task('browser-sync', function() {
var file_path = __dirname;
var explode = file_path.split('htdocs');
browserSync.init({
proxy: "localhost"+explode[1]+'/web'
});
});
gulp.task('sass:development', function() {
gulp.src('styles/main.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: `expanded`,
precision: 10,
includePaths: [
'templates',
'styles',
]
}))
.on('error', swallowError)
.pipe(concat('main.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('web/static'))
.pipe(browserSync.stream());
});
gulp.task('watch:development', function() {
gulp.watch('styles/**/*.scss', ['sass:development']);
gulp.watch('templates/**/*.scss', ['sass:development']);
gulp.watch("templates/**/*.twig").on('change', browserSync.reload);
});
function swallowError (error) {
console.log(error.toString())
this.emit('end')
notifier.notify({
title: 'gulp css error',
message: error.relativePath + ' line '+ error.line,
sound: false,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment