Skip to content

Instantly share code, notes, and snippets.

@darrenjaworski
Last active May 28, 2018 04:31
Show Gist options
  • Save darrenjaworski/1fd97539ae1cb344ed92 to your computer and use it in GitHub Desktop.
Save darrenjaworski/1fd97539ae1cb344ed92 to your computer and use it in GitHub Desktop.
Craft cms gulpfile
var gulp = require('gulp'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
browserSync = require('browser-sync').create(),
autoprefixer = require('gulp-autoprefixer'),
minify = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
rename = require('gulp-rename');
gulp.task('build-css', function() {
gulp.src('./scss/main.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 25 versions']
}))
.pipe(minify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./css'))
.pipe(browserSync.stream());
});
gulp.task('build-js', function() {
gulp.src('./js/*.js')
.pipe(concat('scripts.js'))
.pipe(gulp.dest('./js/min'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('./js/min'));
});
gulp.task('serve', function() {
browserSync.init({
proxy: 'localhost'
});
})
gulp.task('watch', function(){
gulp.watch('./scss/**/*.scss', ['build-css']);
gulp.watch(['../craft/templates/**/*.html', './js/main.js']).on('change', browserSync.reload);
})
gulp.task('default', ['build-css', 'serve', 'watch']);
gulp.task('build', ['build-css', 'build-js']);
{
"name": "craft-cms-gulpfile",
"version": "1.0.0",
"description": "Craft CMS gulpfile.",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://gist.github.com/1fd97539ae1cb344ed92.git"
},
"author": "Darren Jaworski <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://gist.github.com/1fd97539ae1cb344ed92"
},
"homepage": "https://gist.github.com/1fd97539ae1cb344ed92",
"dependencies": {
"browser-sync": "^2.9.11",
"gulp": "^3.9.0",
"gulp-autoprefixer": "^3.1.0",
"gulp-minify-css": "^1.2.1",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.1.0",
"gulp-sourcemaps": "^1.6.0"
}
}
@seb-thomas
Copy link

Hey this looks cool, thanks for sharing!
Do you use MAMP? And what URL are you running your Craft install on? We're still using the project-name.dev kind of URLs while we test in Craft Pro.
I ask because I'm having trouble getting BrowserSync to work. Can see the front end at localhost:3001, but can't login on the same URL due to CORS, and our site requires the user to be logged in.. :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment