I having trouble trying to show the debug grid from susy 2.
base on this sample:
http://sassmeister.com/gist/9533822
I use
body
{
#include container(show);
}
but what Developer Tool Return is:
https://www.dropbox.com/s/pskhjvwd631jux6/Screenshot%202014-08-24%2015.31.37.png?dl=0
the SVG Grid is not there
I start thinking of my gulp Config:
// Include gulp
var gulp = require('gulp'),
// Include Our Plugins
sass = require('gulp-ruby-sass'),
compass = require('gulp-compass'),
prefix = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
rimraf = require('gulp-rimraf'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
plumber = require('gulp-plumber');
livereload = require('gulp-livereload');
//Sass
gulp.task('styles', function() {
return gulp.src('_scss/*.scss')
.pipe(plumber())
.pipe(compass({
// Compass settings that would otherwise go in config.rb
sass: '_scss',
css: 'resources/css',
image: 'resources/img',
//environment: 'production',
//environment: 'development',
style: 'expanded',
relative: true,
//noLineComments: true
require: ['susy', 'breakpoint']
}))
.pipe(prefix({ cascade: true }))
.pipe(gulp.dest('resources/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('resources/css'))
.pipe(notify({ message: 'Styles task complete' }));
});
// Concatenate & Minify JS
gulp.task('pluginsjs', function() {
return gulp.src(['_coffeescript/_plugins.js'])
.pipe(plumber())
.pipe(gulp.dest('resources/js'))
.pipe(rename({basename:'plugins', suffix: '.min'}))
.pipe(gulp.dest('resources/js'))
.pipe(notify({ message: 'Plugins javascript task complete' }));
});
gulp.task('mainjs', function() {
return gulp.src(['_coffeescript/_main.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(plumber())
.pipe(gulp.dest('resources/js'))
.pipe(rename({basename:'main',suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('resources/js'))
.pipe(notify({ message: 'Main javascript task complete' }));
});
// Optimize Images
gulp.task('images', function() {
return gulp.src('_img/**')
.pipe(plumber())
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(gulp.dest('resources/img'))
.pipe(notify({ message: 'Images task complete' }));
});
//Clean everything
gulp.task('rimraf', function() {
return gulp.src(['resources/css', 'resources/js', 'resources/img'], {read: false})
.pipe(rimraf());
});
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('_scss/*.scss', ['styles']);
// Watch .js files
gulp.watch('_coffeescript/*.js', ['pluginsjs','mainjs']);
// Watch image files
gulp.watch('_img/**', ['images']);
//Create LiveReload server
var server = livereload();
//Watch any files in dist/, reload on change
gulp.watch(['dist + /**']).on('change', function(file) {
server.changed(file.path);
});
});
gulp.task('default', ['rimraf'], function() {
gulp.start(['styles', 'pluginsjs', 'mainjs', 'images', 'watch']);
});
But I deactive imagemin or anything that could be affectig , and is the same always... :(
What could it be?
thanks
It looks like you have another image that is overriding the Susy background. Try using the overlay option:
body
{
#include container(show overlay);
}
Related
I'm pretty new to Gulp, but I thought I had a handle on it, until I inherited a WordPress theme that needed some development work on.
I've been compiling my styles with no issues until it came to compiling the editor-styles.scss
This is the basic file structure for my styles:
theme-name
_static
styles
_admin
editor-styles.scss
editor-styles.min.css
admin-styles.scss
admin-styoles.min.css
login-styles.scss
login-styles.min.css
_layout
_block.scss
_header.scss
_utils
_mixins.scss
_variables.scss
styles.scss
styles.css
All changes to any scss file in the _layout and _utils folders are compiled correctly to the styles.css in the main index.
When I edit an scss file in the _admin folder, I need it to compile to the .min.css version in that same folder.
Instead, it's compiling and creating a new _admin folder in the main theme index with .css files.
I know why this is, because that is what I have told my compiling to do in my gulpfile.js
However, I can't get my head around how to split these two sources?
This is my gulpfile.js:
// MODULES
var gulp = require('gulp');
var sass = require('gulp-sass');
var js = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var plumber = require('gulp-plumber');
var gutil = require('gulp-util');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
// COMPILE AND MINIFY SASS
gulp.task('sass', function () {
return gulp.src('./wp-content/themes/theme-name/_static/styles/**/*.scss')
.pipe(plumber())
.pipe(sass.sync().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./wp-content/themes/theme-name'))
.pipe(browserSync.stream())
done();
});
// MINIFY JS
gulp.task('js', function () {
return gulp.src('./wp-content/themes/theme-name/_static/js/*.js')
.pipe(js())
.on('error', onError)
.pipe(rename({
suffix: '.min'
}))
.pipe(concat('all.min.js'))
.pipe(gulp.dest('./wp-content/themes/theme-name/_static/js/min/'))
.pipe(browserSync.stream())
done();
});
// IMAGES
gulp.task('imagemin', function () {
return gulp.src('./wp-content/themes/theme-name/*')
.pipe(imagemin())
.pipe(gulp.dest('./wp-content/themes/theme-name/images'))
done();
});
// BROWSERSYNC
gulp.task('browser-sync', function(done) {
browserSync.init({
proxy: 'http://localhost/project-name'
})
done();
});
// RELOAD
gulp.task('reload', function (done) {
browserSync.reload();
done();
});
// ERROR LOG
var onError = function (err) {
console.log('An error occurred:', gutil.colors.magenta(err.message));
gutil.beep();
this.emit('end');
};
// WATCH
gulp.task('watch', function() {
gulp.watch('./wp-content/themes/theme-name/_static/styles/**/*.scss', gulp.series('sass'));
gulp.watch('./wp-content/themes/theme-name/_static/js/*.js', gulp.series('js'));
gulp.watch('./wp-content/themes/theme-name/images/*', gulp.series('imagemin'));
gulp.watch('./wp-content/themes/theme-name/**/*.php').on('change', browserSync.reload);
gulp.watch('*/theme-name/**/*.php').on('change', browserSync.reload);
});
gulp.task('default', gulp.series('sass', 'js', 'imagemin', 'browser-sync', 'watch'));
Thanks in advance for any help/advice - I'm banging my head against a wall and I'm sure it's something super simple I've overlooked.
There is more than one way to accomplish what you want. You could have separate watch statements triggering separate sass statements for your different directories. The advantage to that is you are not running all your .scss files everytime.
But consider this. Using the gulp-if plugin which allows you to make if/else decisions mid-stream.
const gulpif = require('gulp-if');
const path = require('path'); // needed to get the last directory name in a path
const condition = function (file) {
const match = path.basename(path.dirname(file.path));
return match === "_admin";
}
// COMPILE AND MINIFY SASS
gulp.task('sass', function () {
return gulp.src('./_static/styles/**/*.scss')
.pipe(plumber())
.pipe(sass.sync().on('error', sass.logError))
.pipe(sourcemaps.write())
// if condition is true use first gulp.dest, else use second
// condition is true if current file parent directory is _admin
.pipe(gulpif(condition, gulp.dest('./_static/styles/'), gulp.dest('./')))
.pipe(browserSync.stream());
// done(); // not needed with the return
});
The disadvantage of this method is that all .scss files are re-compiled each time.
If anyone needs to know how to run tasks for separate src and destinations, this is what works for me :) Thanks for your help Mark.
// This is my main sass files.
// It compiles all my sass files, EXCEPT any files in the _admin folder
// and compiles them to styles.css in my main theme index/root
gulp.task('sass', function () {
return gulp.src([
'./wp-content/themes/theme-name/_static/styles/**/*.scss',
'!./wp-content/themes/theme-name/_static/styles/_admin/*.scss'
])
.pipe(plumber())
.pipe(sass.sync().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./wp-content/themes/andra-birkerts-design'))
.pipe(browserSync.stream())
done();
});
// This is my main admin sass file.
// It compiles just the sass files in the _admin folder
// and compiles them to filename.min.css in the same _admin folder
gulp.task('admin_sass', function () {
return gulp.src('./wp-content/themes/theme-name/_static/styles/_admin/*.scss')
.pipe(plumber())
.pipe(sass.sync().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./wp-content/themes/theme-name/_static/styles/_admin'))
.pipe(browserSync.stream())
done();
});
gulp.task('default', gulp.series('sass', 'admin_sass', 'browser-sync', 'watch'));
How do I get the css files to update in the browser like livereload but have php files trigger a full reload? Everything else in my gulpfile is working, but nothing seems to be happening after gulp.dest. There's no errors and the output in my console is:
Starting 'sass'...
Finished 'sass' after 26 ms
write ./\main.css
gulpfile.js
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
browserSync = require('browser-sync').create(),
php = require('gulp-connect-php'),
sourcemaps = require('gulp-sourcemaps');
var paths = {
base: './**/',
webroot: './public_html/',
lib: './public_html/lib/'
};
paths.scssPath = paths.lib + 'scss/**/';
paths.scssMain = paths.scssPath + 'main.scss';
paths.scssAll = paths.scssPath + '*.scss';
paths.phpAll = paths.webroot + '**/*.php';
paths.css = paths.webroot + 'css/';
paths.cssAll = paths.css + '**/*.css';
gulp.task('php', function() {
php.server({ base: 'public_html', port: 8010, keepalive: true });
});
gulp.task('browser-sync', ['php'], function() {
browserSync.init({
proxy: 'localhost:8000/',
port: 8080,
open: true,
notify: false
});
});
gulp.task('sass', function () {
return sass(paths.scssMain)
.on('error', function(err) {
console.error('Error!', err.message);
})
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.css))
.pipe(browserSync.stream({match: '**/*.css'}));
});
gulp.task('default', ['sass', 'browser-sync'], function() {
gulp.watch(paths.scssAll, ['sass']);
gulp.watch([paths.phpAll], browserSync.reload);
});
I just can't get gulp-autoprefixer to work. I was testing it with transitions but when I save my scss file the prefixes don't show up in my css file. Everything else seems to be just fine.
This is my gulp file:
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
sass = require('gulp-sass'),
browserSync = require('browser-sync');
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "./"
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('images', function(){
gulp.src('build/images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('images/'));
});
gulp.task('styles', function(){
gulp.src(['scss/**/*.scss'])
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(sass())
.pipe(autoprefixer('last 2 versions'))
.pipe(gulp.dest('css/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('default', ['browser-sync'], function(){
gulp.watch("scss/**/*.scss", ['styles']);
gulp.watch("*.html", ['bs-reload']);
});
Thank you all for your help!!
UPDATE
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
sass = require('gulp-sass'),
browserSync = require('browser-sync');
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "./"
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('images', function(){
gulp.src('build/images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('images/'));
});
gulp.task('styles', function(){
gulp.src(['scss/**/*.scss'])
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('css/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('default', ['browser-sync'], function(){
gulp.watch("scss/**/*.scss", ['styles']);
gulp.watch("*.html", ['bs-reload']);
});
According to the documentation, the implementation is slightly different to what you have:
const gulp = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
gulp.task('default', () =>
gulp.src('src/app.css')
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('dist'))
);
It now specifically passes an object containing browsers as an array.
This might be dependent upon the version you're using, because I have Gulpfiles that use an older syntax that looks more like yours.
I have an Ionic V1 app and I did ionic setup sass.
I've added the scss in watchPatterns in ionic.config.json. Gulp detects the file change but doesn't compile the scss into the css. Tried a lot of things.
I did ionic setup sass twice. It seems that the sass only compiles into css once I do ionic setup sass.
Here's the gulpfile.js
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var paths = {
sass: ['./scss/**/*.scss']
};
gulp.task('default', ['sass']);
gulp.task('sass', function(done) {
gulp.src('./scss/ionic.app.scss')
.pipe(sass())
.on('error', sass.logError)
.pipe(gulp.dest('./www/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./www/css/'))
.on('end', done);
});
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
});
gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});
I updated to IONIC 2 few days and have the same problem.
Just add these 2 lines to your gulpfile.js:
gulp.task('serve:before', ['default','watch']);
gulp.task('run:before', ['default']);
It's working for me.
I had similar issue and the problem started, when I had upgraded ionic-cli to version 2.x. So I would suggest you to downgrade back to version 1.x.x.; for example I am using last subversion:
npm install -g ionic#1.7.16
For me, now everything works as it was before the upgrade (I am using same gulp file, I also rename "ionic.config.json" back to "ionic.project"). Hope it helps!
Check TomiL's answer, it might be able to help you. If not, try running two cmd's, first type ionic serve, and in the other one type gulp default, or whatever your task name is. here's my gulpfile
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var paths = {
sass: ['./scss/*.scss']
};
gulp.task('default', ['sass']);
gulp.task('sass', function(done) {
gulp.src('./scss/ionic.app.scss')
.pipe(sass())
.on('error', sass.logError)
.pipe(gulp.dest('./www/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./www/css/'))
.on('end', done);
});
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
});
gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});
I've got the same issue. I found out that it's because gulp doesn't compile scss files before 'ionic serve', so just add the task below solved the problem:
gulp.task('serve:before', ['default']);
For the life of me, I cannot somehow find what is wrong with this configuration! After injecting the master.css changes, instead of just reflecting the changes, my browser window automatically reloads although it says "injected". Could someone please help? I have a gulpfile.js with the following configuration:
var paths = {
master: {
styles: 'default/less/master.less',
},
watch: {
styles: 'default/less/**/*.less',
},
dist: {
styles: 'default/less',
}
};
Less Task:
gulp.task('less', function(){
'use strict';
gulp.src(paths.master.styles)
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(less({compress:false}))
.on('error', function (err) {
gutil.log(err);
this.emit('end');
})
.pipe(autoprefix())
.pipe(sourcemaps.write('../sourcemaps', {
includeContent: false, // Otherwise all the CSS would be included
sourceRoot: paths.dist.styles
}))
.pipe(gulp.dest(paths.dist.styles))
.on('error', gutil.log)
.pipe(browserSync.stream());
});
Browsersync Task:
gulp.task('browser-sync', ['less'], function() {
'use strict';
browserSync.init({
proxy: "http://mywebsite.local",
stream:true
});
gulp.watch(paths.watch.styles, ['less']);
});
And at the end:
gulp.task('default', ['less', 'browser-sync']);
I see a notification that the changes were injected, my terminal says master.css and master.css.map changed and my changes in the less file are reflected as well, but somehow the browser reloads which I don't want at all for the css compilation.