Gulp is not compiling sass to css - gulp

I am not able to get the sass code I write to compile into CSS when I use any of the following commands:
gulp watch
gulp scss-for-prod
gulp scripts-for-prod
The strange thing is though that fork picks up when I make a change

SOLVED: add a clean package.json file
This is the Gulp.js
// Defining requirements
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
var cssnano = require('gulp-cssnano');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var terser = require('gulp-terser');
//var uglify = require('gulp-uglify');
var merge2 = require('merge2');
var imagemin = require('gulp-imagemin');
var ignore = require('gulp-ignore');
var rimraf = require('gulp-rimraf');
var clone = require('gulp-clone');
var merge = require('gulp-merge');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var del = require('del');
var cleanCSS = require('gulp-clean-css');
var gulpSequence = require('gulp-sequence');
var replace = require('gulp-replace');
var autoprefixer = require('gulp-autoprefixer');
//var babel = require('gulp-babel');
var webpack = require('webpack-stream');
//var haml = require('gulp-haml');
// Configuration file to keep your code DRY
var cfg = require('./gulpconfig.json');
var paths = cfg.paths;
// Run:
// gulp sass + cssnano + rename
// Prepare the min.css for production (with 2 pipes to be sure that "theme.css" == "theme.min.css")
gulp.task('scss-for-prod', function () {
var source = gulp.src(paths.sass + '/*.scss')
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sass());
var pipeoutput = source.pipe(clone())
//.pipe(minifycss())
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.css));
return pipeoutput;
});
// Run:
// gulp sourcemaps + sass + reload(browserSync)
// Prepare the child-theme.css for the development environment
gulp.task('scss-for-dev', function () {
gulp.src(paths.sass + '/*.scss')
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sass())
.pipe(sourcemaps.write(undefined, { sourceRoot: null }))
.pipe(gulp.dest(paths.css));
});
gulp.task('watch-scss', ['browser-sync'], function () {
gulp.watch(paths.sass + '/**/*.scss', ['scss-for-dev']);
});
// Run:
// gulp sass
// Compiles SCSS files in CSS
gulp.task('sass', function () {
var stream = gulp.src(paths.sass + '/*.scss')
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sass({ errLogToConsole: true }))
.pipe(autoprefixer('last 2 versions'))
.pipe(gulp.dest(paths.css));
return stream;
});
// Run:
// gulp watch
// Starts watcher. Watcher runs gulp sass task on changes
gulp.task('watch', function () {
gulp.watch(paths.haml + '/**/*.haml', ['convert-haml']);
gulp.watch(paths.sass + '/**/*.scss', ['styles']);
gulp.watch([paths.dev + '/js/**/*.js', 'js/**/*.js', '!js/theme.js', '!js/theme.min.js'], ['scripts']);
//Inside the watch task.
gulp.watch(paths.imgsrc + '/**', ['imagemin-watch']);
//browserSync.reload();
});
/**
* Ensures the 'imagemin' task is complete before reloading browsers
* #verbose
*/
gulp.task('imagemin-watch', ['imagemin'], function (done) {
browserSync.reload();
done();
});
// Run:
// gulp imagemin
// Running image optimizing task
gulp.task('imagemin', function () {
gulp.src(paths.imgsrc + '/**')
.pipe(imagemin())
.pipe(gulp.dest(paths.img));
});
// Run:
// gulp cssnano
// Minifies CSS files
gulp.task('cssnano', function () {
return gulp.src(paths.css + '/theme.css')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(rename({ suffix: '.min' }))
.pipe(cssnano({ discardComments: { removeAll: true } }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.css));
});
gulp.task('minifycss', function () {
return gulp.src(paths.css + '/theme.css')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(cleanCSS({ compatibility: '*' }))
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.css));
});
gulp.task('cleancss', function () {
return gulp.src(paths.css + '/*.min.css', { read: false }) // Much faster
.pipe(ignore('theme.css'))
.pipe(rimraf());
});
//gulp.task( 'convert-haml', function( callback ) {
// gulp.src('./haml/**/*.haml')
// .pipe(haml({ext: '.php'}))
// .pipe(gulp.dest('./'));
//} );
gulp.task('styles', function (callback) {
//gulpSequence('sass', 'minifycss')(callback);
gulpSequence('sass', 'cleancss')(callback);
});
// Run:
// gulp browser-sync
// Starts browser-sync task for starting the server.
gulp.task('browser-sync', function () {
browserSync.init(cfg.browserSyncWatchFiles, cfg.browserSyncOptions);
});
// Run:
// gulp watch-bs
// Starts watcher with browser-sync. Browser-sync reloads page automatically on your browser
gulp.task('watch-bs', ['browser-sync', 'watch', 'scripts'], function () {
});
// gulp scripts.
// Uglifies and concat all JS files into one
gulp.task('scripts', function () {
var scripts = [
//paths.dev + '/js/paginate.js',
//paths.dev + "/js/Select2.js",
paths.dev + "/js/slick/slick.js",
paths.dev + '/js/main.js',
];
gulp.src(scripts)
//.pipe(babel())
.pipe(webpack({
mode: 'development'
}))
.pipe(concat('theme.js'))
.pipe(gulp.dest(paths.js));
});
gulp.task('scripts-for-prod', function () {
var scripts = [
//paths.dev + '/js/paginate.js',
//paths.dev + "/js/Select2.js",
paths.dev + "/js/slick/slick.js",
paths.dev + '/js/main.js',
];
gulp.src(scripts)
//.pipe(babel())
.pipe(webpack({
mode: 'development'
}))
.pipe(concat('theme.min.js'))
//.pipe( uglify().on('error', function(e){
// console.log(e);
// }) )
/*.pipe(terser().on('error', function(e){
console.log(e);
}) )*/
.pipe(gulp.dest(paths.js));
});
// Deleting any file inside the /src folder
gulp.task('clean-source', function () {
return del(['src/**/*']);
});
// Run:
// gulp copy-assets.
// Copy all needed dependency assets files from bower_component assets to themes /js, /scss and /fonts folder. Run this task after bower install or bower update
////////////////// All Bootstrap SASS Assets /////////////////////////
gulp.task('copy-assets', function () {
// Tachyons CSS
//var stream = gulp.src( paths.node + 'tachyons-sass/tachyons.scss' )
//.pipe( gulp.dest( paths.dev + '/sass/tachyons-sass' ) );
var stream = gulp.src(paths.node + 'normalize-scss/sass/**/*')
.pipe(gulp.dest(paths.dev + '/sass/normalize-scss'));
//gulp.src( paths.node + 'tachyons-sass/scss/*.scss' )
//.pipe( gulp.dest( paths.dev + '/sass/tachyons-sass/scss' ) );
// Flexbox Grid
//gulp.src( paths.node + 'flexboxgrid-sass/flexboxgrid.scss' )
//.pipe( gulp.dest( paths.dev + '/sass/flexboxgrid-sass' ) );
//gulp.src( paths.node + 'sass-flex-mixin/**/*' )
//.pipe( gulp.dest( paths.dev + '/sass/sass-flex-mixin' ) );
gulp.src(paths.node + '#drewbot/sass-flexbox-grid/public/sass-flexbox/scss/**/*')
.pipe(gulp.dest(paths.dev + '/sass/sass-flexbox-grid'));
////////////////// All Bootstrap 4 Assets /////////////////////////
// Copy all JS files
//var stream = gulp.src( paths.node + 'bootstrap/dist/js/**/*.js' )
// .pipe( gulp.dest( paths.dev + '/js/bootstrap4' ) );
// Copy all Bootstrap SCSS files
//gulp.src( paths.node + 'bootstrap/scss/**/*.scss' )
// .pipe( gulp.dest( paths.dev + '/sass/bootstrap4' ) );
////////////////// End Bootstrap 4 Assets /////////////////////////
gulp
.src(paths.node + "slick-carousel-latest/slick/slick.js")
.pipe(gulp.dest(paths.dev + "/js/utils/slick"));
gulp
.src(paths.node + "slick-carousel-latest/slick/*")
.pipe(gulp.dest(paths.dev + "/sass/slick"));
gulp
.src(paths.node + "slick-carousel-latest/slick/fonts/*")
.pipe(gulp.dest(paths.css + "/fonts"));
//gulp.src(paths.node + 'vanillajs-datepicker/dist/**/*')
// .pipe(gulp.dest(paths.dev + '/js/utils/vanillajs-datepicker'));
gulp.src(paths.node + 'js-datepicker/src/**/*')
.pipe(gulp.dest(paths.dev + '/js/utils/js-datepicker'));
gulp.src(paths.node + 'js-datepicker/dist/**/*')
.pipe(gulp.dest(paths.dev + '/js/utils/js-datepicker'));
// Copy Sass Mq
gulp.src(paths.node + 'sass-mq/_mq.scss')
.pipe(gulp.dest(paths.dev + '/sass/sass-mq'));
// Copy all Font Awesome Fonts
gulp.src(paths.node + '#fortawesome/fontawesome-free/**/*.{ttf,woff,woff2,eot,svg}')
.pipe(gulp.dest('./fonts/fortawesome'));
// Copy all Font Awesome SCSS files
gulp.src(paths.node + '#fortawesome/fontawesome-free/scss/**/*.scss')
.pipe(gulp.dest(paths.dev + '/sass/fortawesome'));
return stream;
});
// Deleting the files distributed by the copy-assets task
gulp.task('clean-vendor-assets', function () {
return del([
paths.dev + '/js/vanillajs-datepicker/**',
paths.dev + '/sass/sass-flex-mixin/**',
paths.dev + '/sass/flexboxgrid-sass/**',
'./fonts/*wesome*.{ttf,woff,woff2,eot,svg}',
paths.dev + '/sass/fortawesome/**',
paths.dev + "/js/utils/slick/**",
paths.dev + "/sass/slick/**",
paths.fonts + "/slick/**",
paths.vendor !== '' ? (paths.js + paths.vendor + '/**') : ''
]);
});
// Run
// gulp dist
// Copies the files to the /dist folder for distribution as simple theme
gulp.task('dist', ['clean-dist'], function () {
return gulp.src(['**/*', '!' + paths.bower, '!' + paths.bower + '/**', '!' + paths.node, '!' + paths.node + '/**', '!' + paths.dev, '!' + paths.dev + '/**', '!' + paths.dist, '!' + paths.dist + '/**', '!' + paths.distprod, '!' + paths.distprod + '/**', '!' + paths.sass, '!' + paths.sass + '/**', '!readme.txt', '!readme.md', '!package.json', '!package-lock.json', '!gulpfile.js', '!gulpconfig.json', '!CHANGELOG.md', '!.travis.yml', '!jshintignore', '!codesniffer.ruleset.xml', '*'], { 'buffer': false })
//.pipe( replace( '/js/jquery.slim.min.js', '/js' + paths.vendor + '/jquery.slim.min.js', { 'skipBinary': true } ) )
.pipe(replace('/js/main.js', '/js' + paths.vendor + '/main.js', { 'skipBinary': true }))
.pipe(gulp.dest(paths.dist));
});
// Deleting any file inside the /dist folder
gulp.task('clean-dist', function () {
return del([paths.dist + '/**']);
});
// Run
// gulp dist-product
// Copies the files to the /dist-prod folder for distribution as theme with all assets
gulp.task('dist-product', ['clean-dist-product'], function () {
return gulp.src(['**/*', '!' + paths.bower, '!' + paths.bower + '/**', '!' + paths.node, '!' + paths.node + '/**', '!' + paths.dist, '!' + paths.dist + '/**', '!' + paths.distprod, '!' + paths.distprod + '/**', '*'])
.pipe(gulp.dest(paths.distprod));
});
// Deleting any file inside the /dist-product folder
gulp.task('clean-dist-product', function () {
return del([paths.distprod + '/**']);
});

Related

Gulp 4 BrowSersync not refreshing the webpage when SCSS files changed

I just started to use Gulp with BrowserSync.
Please, help me with following issue: When I save my SCSS files BrowserSync not refreshes the webpage but saves files OK. Here is what happening in the console:
[21:37:48] Starting 'css'...
[Browsersync] 1 file changed (main.min.css)
[21:37:48] Finished 'css' after 206 ms
So no message
"[Browsersync] Reloading Browsers..."
This problem only with SCSS files, JS and HTML work correctly. Here is my gulpfile.js:
let project_folder = require("path").basename(__dirname);
let source_folder = "#src";
let fs = require('fs');
let path = {
build: {
html: project_folder + "/",
css: project_folder + "/css/",
js: project_folder + "/js/",
img: project_folder + "/images/",
fonts: project_folder + "/fonts/",
},
src: {
html: [source_folder + "/*.html", "!" + source_folder + "/_*.html"],
css: source_folder + "/styles/main.scss",
js: source_folder + "/js/main.js",
img: source_folder + "/images/**/*.{jpg,png,svg,gif,ico,webp}",
fonts: source_folder + "/fonts/*.{ttf,otf,woff,woff2}",
},
watch: {
html: source_folder + "/**/*.html",
css: source_folder + "/styles/**/*.scss",
js: source_folder + "/js/**/*.js",
img: source_folder + "/images/**/*.{jpg,png,svg,gif,ico,webp}"
},
clean: "./" + project_folder + "/"
}
let { src, dest } = require('gulp'),
gulp = require('gulp'),
browsersync = require("browser-sync").create(),
include = require('gulp-include'),
del = require("del"),
scss = require("gulp-sass"),
autoprefixer = require("gulp-autoprefixer"),
group_media = require("gulp-group-css-media-queries"),
clean_css = require("gulp-clean-css"),
rename = require("gulp-rename"),
uglify = require("gulp-uglify-es").default,
imagemin = require("gulp-imagemin"),
webp = require('gulp-webp'),
webphtml = require('gulp-webp-html'),
webpcss = require("gulp-webpcss"),
svgSprite = require('gulp-svg-sprite');
function browserSync(params) {
browsersync.init({
server: {
baseDir: "./" + project_folder + "/"
},
port: 3000,
notify: false
})
}
function html() {
return src(path.src.html)
.pipe(include())
.pipe(webphtml())
.pipe(dest(path.build.html))
.pipe(browsersync.stream())
}
function css() {
return src(path.src.css)
.pipe(
scss({
outputStyle: "expanded"
})
)
.pipe(
group_media()
)
.pipe(
autoprefixer({
overrideBrowserslist: ["last 5 versions"],
cascade: true
})
)
.pipe(webpcss())
.pipe(dest(path.build.css))
.pipe(clean_css())
.pipe(
rename({
extname: ".min.css"
})
)
.pipe(dest(path.build.css))
.pipe(browsersync.stream())
}
function js() {
return src(path.src.js)
// .pipe(fileinclude())
.pipe(include())
.pipe(dest(path.build.js))
.pipe(
uglify()
)
.pipe(
rename({
extname: ".min.js"
})
)
.pipe(dest(path.build.js))
.pipe(browsersync.stream())
}
function images() {
return src(path.src.img)
.pipe(
webp({
quality: 70
})
)
.pipe(dest(path.build.img))
.pipe(src(path.src.img))
.pipe(
imagemin({
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
interlaced: true,
optimizationLevel: 3 // 0 to 7
})
)
.pipe(dest(path.build.img))
.pipe(browsersync.stream())
}
function fonts() {
return src(path.src.fonts)
.pipe(dest(path.build.fonts));
};
gulp.task('svgSprite', function () {
return gulp.src([source_folder + '/iconsprite/*.svg'])
.pipe(svgSprite({
mode: {
stack: {
sprite: "../icons/icons.svg", //sprite file name
example: true
}
},
}
))
.pipe(dest(path.build.img))
})
function watchFiles(params) {
gulp.watch([path.watch.html], html);
gulp.watch([path.watch.css], css);
gulp.watch([path.watch.js], js);
gulp.watch([path.watch.img], images);
}
function clean(params) {
return del(path.clean);
}
let build = gulp.series(clean, gulp.parallel(js, css, html, images, fonts));
let watch = gulp.parallel(build, watchFiles, browserSync);
exports.fonts = fonts;
exports.images = images;
exports.js = js;
exports.css = css;
exports.html = html;
exports.build = build;
exports.watch = watch;
exports.default = watch;

How do I fix Browser Sync and Live Reload in my Gulpfile?

I'm trying to get Browser Sync and Live Reload working in my gulp file but it doesn't want to run correctly.
I want to be able to detect any file change in 'src' and my 'templates' folder which are both contained within the root. The gulp file is detecting the changes in the src folder fine but the template files are not getting reloaded in the browser on save.
Note:
I have the live reload chrome browser extension.
I'm not compiling the templates folder but am compiling everything in src to the web destination folder.
The Gulp File:
// -------------------- Configuration Settings --------------------
var config = {};
//basics
config.siteName = 'Franklin';
config.proxyDomain = 'https://franklin.test';
//source directory
config.src = 'src/';
//twig templates
config.templates = 'templates';
//destinations
config.dest = 'web/';
config.destJS = config.dest + 'assets/js';
config.destCSS = config.dest + 'assets/css';
config.destFonts = config.dest + 'assets/fonts';
config.destPWA = config.dest;
//globs
config.globs = {
templates : config.templates + '/**/*.twig',
scss : config.src + 'scss/**/*.scss',
js : {
individual : config.src + 'js/individual/**/*.js',
combined : [
config.src + 'js/combined/libs/*.js',
config.src + 'js/combined/plugins/*.js',
config.src + 'js/combined/pluginSubs/*.js',
config.src + 'js/combined/site/*.js',
config.src + 'js/combined/site.js'
]
},
fonts : config.src + 'fonts/**/*',
pwa : config.src + 'pwa/**/*',
watched : [
config.templates + '/**/*.twig',
config.destJS + '/**/*.min.js',
config.destCSS + '/**/*.min.css',
config.destFonts + '/**/*',
config.destPWA + '/**/*'
]
};
//browser sync
config.browserSync = {
files: config.globs.watched,
proxy: config.proxyDomain
};
// -------------------- Require Statements --------------------
var gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
livereload = require('gulp-livereload'),
browserSync = require('browser-sync').create(),
newer = require('gulp-newer'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
size = require('gulp-size'),
uglify = require('gulp-uglify'),
watch = require('gulp-watch'),
path = require('path'),
cssnano = require('gulp-cssnano'),
sourcemaps = require('gulp-sourcemaps'),
lazypipe = require('lazypipe'),
fs = require('fs');
// -------------------- Notification Icon Detection --------------------
/**
* Checks to see if a file exists.
*
* #param filePath
* #returns {*}
*/
function fileExists(filePath)
{
try {
return fs.statSync(filePath).isFile();
} catch (err) {
return false;
}
}
var iconPath = path.join(__dirname, 'gulp.png');
var icon = fileExists( iconPath ) ? iconPath : null;
// -------------------- Plumber Error Handler --------------------
var plumberErrorHandler = function(err) {
console.log( 'plumber error! "' + err.message + '"' );
notify.onError({
title: config.siteName,
message: "Error: <%= err.message %>",
sound: 'Pop'
});
this.emit('end');
};
// -------------------- Processors --------------------
//individual scripts (not combined)
var jsIndividualScripts = lazypipe()
.pipe(plumber, {errorHandler: plumberErrorHandler})
.pipe(newer, { dest: config.destJS, ext: '.min.js' })
.pipe(gulp.dest, config.destJS)
.pipe(size, {showFiles: true})
.pipe(uglify)
.pipe(rename, { suffix: '.min' })
.pipe(gulp.dest, config.destJS)
.pipe(size, {showFiles: true});
//combined scripts
var jsCombinedScripts = lazypipe()
.pipe(plumber, {errorHandler: plumberErrorHandler})
.pipe(newer, config.dest + 'js/scripts.min.js')
.pipe(concat, 'scripts.js')
.pipe(gulp.dest, config.destJS)
.pipe(size, {showFiles: true})
.pipe(uglify)
.pipe(rename, { suffix: '.min' })
.pipe(gulp.dest, config.destJS)
.pipe(size, {showFiles: true});
//scss compiling
var scssProcessing = lazypipe()
.pipe(plumber, {errorHandler: plumberErrorHandler})
.pipe(sass, {outputStyle: ':compact'})
.pipe(autoprefixer, 'last 2 version')
.pipe(gulp.dest, config.destCSS)
.pipe(size, {showFiles: true})
.pipe(rename, { suffix: '.min' })
.pipe(sourcemaps.init)
.pipe(cssnano)
.pipe(sourcemaps.write, '.')
.pipe(gulp.dest, config.destCSS)
.pipe(size, {showFiles: true});
//fonts compiling
var fontsProcessing = lazypipe()
.pipe(plumber, {errorHandler: plumberErrorHandler})
.pipe(gulp.dest, config.destFonts);
//pwa compiling
var pwaProcessing = lazypipe()
.pipe(plumber, { errorHandler: plumberErrorHandler })
.pipe(gulp.dest, config.destPWA);
// -------------------- Tasks --------------------
//styles task
gulp.task('styles', function() {
if ( browserSync.active ) {
return gulp.src(config.globs.scss)
.pipe(scssProcessing())
.pipe(browserSync.reload({stream:true}));
}
return gulp.src(config.globs.scss).pipe(scssProcessing());
});
//template task
gulp.task('templates', function() {
if ( browserSync.active ) {
return gulp.src(config.globs.templates)
.pipe(browserSync.reload({stream:true}));
}
});
//scripts individual task
gulp.task('scripts-individual', function() {
return gulp.src(config.globs.js.individual).pipe(jsIndividualScripts());
});
//scripts combined task
gulp.task('scripts-combined', function() {
return gulp.src(config.globs.js.combined).pipe(jsCombinedScripts());
});
//fonts task
gulp.task('fonts', function() {
return gulp.src(config.globs.fonts).pipe(fontsProcessing());
});
//pwa task
gulp.task('pwa', function () {
return gulp.src(config.globs.pwa).pipe(pwaProcessing());
});
//watch task
gulp.task('live', function() {
//watch all .scss files
gulp.watch(config.globs.scss, ['styles']);
//watch all twig template files
gulp.watch(config.globs.templates, ['templates']);
//watch each individual .js file
watch(config.globs.js.individual).pipe(jsIndividualScripts());
//watch all combined .js files
gulp.watch(config.globs.js.combined, ['scripts-combined']);
});
//default task - one time styles and scripts
gulp.task('default', ['styles', 'templates', 'scripts-individual', 'scripts-combined', 'fonts', 'pwa']);
//start browser-sync server
gulp.task('serve-bs', ['live'], function() {
browserSync.init(config.browserSync)
});
//start livereload
gulp.task('watch', ['live'], function() {
livereload.listen();
//watch for changes on transpired templates, css, and js files
gulp.watch(config.globs.watched, function(event) {
gulp.src(event.path)
.pipe(plumber({errorHandler: plumberErrorHandler}))
.pipe(livereload())
.pipe(notify({
title: config.siteName,
message: event.type + ': ' + event.path.replace(__dirname, '').replace(/\\/g, '/') + ' was reloaded',
sound: 'Pop',
icon: icon
})
);
});
});

Gulp starts but do nothing

I'm using underscore with sass to create a theme, and I'm using gulp as task runner.
The problem is that after wtaching nothing happens. I tried to perform a single task but once more time nothing. To be sure I performed js task javascript too
here the code:
var themename = 'mytheme';
var gulp = require('gulp'),
// Prepare and optimize code etc
autoprefixer = require('autoprefixer'),
browserSync = require('browser-sync').create(),
image = require('gulp-image'),
jshint = require('gulp-jshint'),
postcss = require('gulp-postcss'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
// Only work with new or updated files
newer = require('gulp-newer'),
// Name of working theme folder
root = '../' + themename + '/',
scss = root + 'sass/',
js = root + 'js/',
img = root + 'images/',
languages = root + 'languages/';
// CSS via Sass and Autoprefixer
gulp.task('css', function() {
return gulp.src(scss + '{style.scss,rtl.scss}')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded',
indentType: 'tab',
indentWidth: '1'
}).on('error', sass.logError))
.pipe(postcss([
autoprefixer('last 2 versions', '> 1%')
]))
.pipe(sourcemaps.write(scss + 'maps'))
.pipe(gulp.dest(root));
});
// Optimize images through gulp-image
gulp.task('images', function() {
return gulp.src(img + 'RAW/**/*.{jpg,JPG,png}')
.pipe(newer(img))
.pipe(image())
.pipe(gulp.dest(img));
});
// JavaScript
gulp.task('javascript', function() {
return gulp.src([js + '*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(gulp.dest(js));
});
// Watch everything
gulp.task('watch', function() {
browserSync.init({
open: 'external',
proxy: 'localhost/mysite',
port: 8080
});
gulp.watch([root + '**/*.css', root + '**/*.scss' ], ['css']);
gulp.watch(js + '**/*.js', ['javascript']);
gulp.watch(img + 'RAW/**/*.{jpg,JPG,png}', ['images']);
gulp.watch(root + '**/*').on('change', browserSync.reload);
});
// Default task (runs at initiation: gulp --verbose)
gulp.task('default', ['watch']);

JHipster - Some CSS files did not appear in vendor file made by Gulp

I have this in main CSS:
And My vendor is this:
Why when I run Production mode material-icons.css and md-data-table.css did not appear?
Gulpfile.js
// Generated on 2016-04-23 using generator-jhipster 3.0.0
'use strict';
var gulp = require('gulp'),
rev = require('gulp-rev'),
templateCache = require('gulp-angular-templatecache'),
htmlmin = require('gulp-htmlmin'),
imagemin = require('gulp-imagemin'),
ngConstant = require('gulp-ng-constant-fork'),
eslint = require('gulp-eslint'),
es = require('event-stream'),
flatten = require('gulp-flatten'),
del = require('del'),
wiredep = require('wiredep').stream,
runSequence = require('run-sequence'),
browserSync = require('browser-sync'),
KarmaServer = require('karma').Server,
plumber = require('gulp-plumber'),
changed = require('gulp-changed'),
gulpIf = require('gulp-if'),
inject = require('gulp-inject'),
angularFilesort = require('gulp-angular-filesort');
var handleErrors = require('./gulp/handleErrors'),
serve = require('./gulp/serve'),
util = require('./gulp/utils'),
build = require('./gulp/build');
var config = require('./gulp/config');
gulp.task('clean', function () {
return del([config.dist], { dot: true });
});
gulp.task('copy', function () {
return es.merge(
gulp.src(config.bower + 'bootstrap/fonts/*.*')
.pipe(plumber({errorHandler: handleErrors}))
.pipe(changed(config.dist + 'content/fonts/'))
.pipe(rev())
.pipe(gulp.dest(config.dist + 'content/fonts/'))
.pipe(rev.manifest(config.revManifest, {
base: config.dist,
merge: true
}))
.pipe(gulp.dest(config.dist)),
gulp.src(config.app + 'content/**/*.{woff,woff2,svg,ttf,eot,otf}')
.pipe(plumber({errorHandler: handleErrors}))
.pipe(changed(config.dist + 'content/fonts/'))
.pipe(flatten())
.pipe(rev())
.pipe(gulp.dest(config.dist + 'content/fonts/'))
.pipe(rev.manifest(config.revManifest, {
base: config.dist,
merge: true
}))
.pipe(gulp.dest(config.dist)),
gulp.src([config.app + 'robots.txt', config.app + 'favicon.ico', config.app + '.htaccess'], { dot: true })
.pipe(plumber({errorHandler: handleErrors}))
.pipe(changed(config.dist))
.pipe(gulp.dest(config.dist))
);
});
gulp.task('images', function () {
return gulp.src(config.app + 'content/images/**')
.pipe(plumber({errorHandler: handleErrors}))
.pipe(changed(config.dist + 'content/images'))
.pipe(imagemin({optimizationLevel: 5, progressive: true, interlaced: true}))
.pipe(rev())
.pipe(gulp.dest(config.dist + 'content/images'))
.pipe(rev.manifest(config.revManifest, {
base: config.dist,
merge: true
}))
.pipe(gulp.dest(config.dist))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('styles', [], function () {
return gulp.src(config.app + 'content/css')
.pipe(browserSync.reload({stream: true}));
});
gulp.task('inject', function () {
return gulp.src(config.app + 'index.html')
.pipe(inject(gulp.src(config.app + 'app/**/*.js').pipe(angularFilesort()), {relative: true}))
.pipe(gulp.dest(config.app));
});
gulp.task('wiredep', ['wiredep:test', 'wiredep:app']);
gulp.task('wiredep:app', function () {
var stream = gulp.src(config.app + 'index.html')
.pipe(plumber({errorHandler: handleErrors}))
.pipe(wiredep({
exclude: [
/angular-i18n/, // localizations are loaded dynamically
'bower_components/bootstrap/dist/js/' // exclude bootstrap js files as we use ui-bootstrap
]
}))
.pipe(gulp.dest(config.app));
return stream;
});
gulp.task('wiredep:test', function () {
return gulp.src(config.test + 'karma.conf.js')
.pipe(plumber({errorHandler: handleErrors}))
.pipe(wiredep({
exclude: [
/angular-i18n/, // localizations are loaded dynamically
/angular-scenario/,
'bower_components/bootstrap/dist/js/' // exclude Bootstrap js files as we use ui-bootstrap
],
ignorePath: /\.\.\/\.\.\//, // remove ../../ from paths of injected JavaScript files
devDependencies: true,
fileTypes: {
js: {
block: /(([\s\t]*)\/\/\s*bower:*(\S*))(\n|\r|.)*?(\/\/\s*endbower)/gi,
detect: {
js: /'(.*\.js)'/gi
},
replace: {
js: '\'src/{{filePath}}\','
}
}
}
}))
.pipe(gulp.dest(config.test));
});
gulp.task('assets:prod', ['images', 'styles', 'html'], build);
gulp.task('html', function () {
return gulp.src(config.app + 'app/**/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(templateCache({
module: 'registroApp',
root: 'app/',
moduleSystem: 'IIFE'
}))
.pipe(gulp.dest(config.tmp));
});
gulp.task('ngconstant:dev', function () {
return ngConstant({
dest: 'app.constants.js',
name: 'registroApp',
deps: false,
noFile: true,
interpolate: /\{%=(.+?)%\}/g,
wrap:
'(function () {\n' +
' "use strict";\n' +
' // DO NOT EDIT THIS FILE, EDIT THE GULP TASK NGCONSTANT SETTINGS INSTEAD WHICH GENERATES THIS FILE\n' +
' {%= __ngModule %}\n' +
'})();\n',
constants: {
ENV: 'dev',
VERSION: util.parseVersion()
}
})
.pipe(gulp.dest(config.app + 'app/'));
});
gulp.task('ngconstant:prod', function () {
return ngConstant({
dest: 'app.constants.js',
name: 'registroApp',
deps: false,
noFile: true,
interpolate: /\{%=(.+?)%\}/g,
wrap:
'(function () {\n' +
' "use strict";\n' +
' // DO NOT EDIT THIS FILE, EDIT THE GULP TASK NGCONSTANT SETTINGS INSTEAD WHICH GENERATES THIS FILE\n' +
' {%= __ngModule %}\n' +
'})();\n',
constants: {
ENV: 'prod',
VERSION: util.parseVersion()
}
})
.pipe(gulp.dest(config.app + 'app/'));
});
// check app for eslint errors
gulp.task('eslint', function () {
return gulp.src(['gulpfile.js', config.app + 'app/**/*.js'])
.pipe(plumber({errorHandler: handleErrors}))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
// check app for eslint errors anf fix some of them
gulp.task('eslint:fix', function () {
return gulp.src(config.app + 'app/**/*.js')
.pipe(plumber({errorHandler: handleErrors}))
.pipe(eslint({
fix: true
}))
.pipe(eslint.format())
.pipe(gulpIf(util.isLintFixed, gulp.dest(config.app + 'app')));
});
gulp.task('test', ['wiredep:test', 'ngconstant:dev'], function (done) {
new KarmaServer({
configFile: __dirname + '/' + config.test + 'karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('watch', function () {
gulp.watch('bower.json', ['install']);
gulp.watch(['gulpfile.js', 'pom.xml'], ['ngconstant:dev']);
gulp.watch(config.app + 'content/css/**/*.css', ['styles']);
gulp.watch(config.app + 'content/images/**', ['images']);
gulp.watch(config.app + 'app/**/*.js', ['inject']);
gulp.watch([config.app + '*.html', config.app + 'app/**', config.app + 'i18n/**']).on('change', browserSync.reload);
});
gulp.task('install', function () {
runSequence(['wiredep', 'ngconstant:dev'], 'inject');
});
gulp.task('serve', function () {
runSequence('install', serve);
});
gulp.task('build', ['clean'], function (cb) {
runSequence(['copy', 'wiredep:app', 'ngconstant:prod'], 'inject', 'assets:prod', cb);
});
gulp.task('default', ['serve']);
Build.js (For gulp task)
var fs = require('fs'),
gulp = require('gulp'),
lazypipe = require('lazypipe'),
footer = require('gulp-footer'),
sourcemaps = require('gulp-sourcemaps'),
rev = require('gulp-rev'),
htmlmin = require('gulp-htmlmin'),
ngAnnotate = require('gulp-ng-annotate'),
prefix = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
uglify = require('gulp-uglify'),
useref = require("gulp-useref"),
revReplace = require("gulp-rev-replace")
plumber = require('gulp-plumber'),
gulpIf = require('gulp-if'),
handleErrors = require('./handleErrors');
var config = require('./config');
var initTask = lazypipe()
.pipe(sourcemaps.init)
.pipe(footer, ';');
var jsTask = lazypipe()
.pipe(ngAnnotate)
.pipe(uglify);
var cssTask = lazypipe()
.pipe(prefix)
.pipe(cssnano);
module.exports = function() {
var templates = fs.readFileSync(config.tmp + '/templates.js');
var manifest = gulp.src(config.revManifest);
return gulp.src([config.app + '**/*.html',
'!' + config.app + 'app/**/*.html',
'!' + config.app + 'swagger-ui/**/*',
'!' + config.bower + '**/*.html'])
.pipe(plumber({errorHandler: handleErrors}))
//init sourcemaps and prepend semicolon
.pipe(useref({}, initTask))
//append html templates
.pipe(gulpIf('**/app.js', footer(templates)))
.pipe(gulpIf('*.js', jsTask()))
.pipe(gulpIf('*.css', cssTask()))
.pipe(gulpIf('*.html', htmlmin({collapseWhitespace: true})))
.pipe(gulpIf('**/*.!(html)', rev()))
.pipe(revReplace({manifest}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.dist));
}
Bower.json
{
"version": "0.0.0",
"name": "registro",
"appPath": "src/main/webapp/",
"testPath": "src/test/javascript/spec",
"dependencies": {
"angular": "1.5.2",
"angular-aria": "1.5.2",
"angular-loading-bar": "0.9.0",
"angular-resource": "1.5.2",
"angular-sanitize": "1.5.2",
"angular-translate": "2.11.0",
"angular-translate-interpolation-messageformat": "2.11.0",
"angular-translate-loader-partial": "2.11.0",
"angular-translate-storage-cookie": "2.11.0",
"angular-ui-router": "0.2.18",
"angular-cache-buster": "0.4.3",
"angular-cookies": "1.5.2",
"angular-dynamic-locale": "0.1.30",
"angular-i18n": "1.5.2",
"angular-bootstrap": "1.2.5",
"bootstrap-ui-datetime-picker": "2.2.3",
"angular-material": "1.0.7",
"material-design-icons": "^2.2.3",
"ngstorage": "0.3.10",
"jquery": "2.2.2",
"json3": "3.3.2",
"modernizr": "3.3.1",
"ng-file-upload": "12.0.4",
"ngInfiniteScroll": "1.2.2",
"swagger-ui": "2.1.4",
"angular-material-data-table": "^0.10.8"
},
"devDependencies": {
"angular-mocks": "1.5.2",
"angular-scenario": "1.5.2"
},
"overrides": {
"angular": {
"dependencies": {
"jquery": "2.2.2"
}
},
"material-design-icons": {
"main": [
"iconfont/material-icons.css"
]
},
"messageformat": {
"main": [
"messageformat.js",
"locale/es.js",
"locale/en.js"
]
}
},
"resolutions": {
"angular": "1.5.2",
"angular-cookies": "1.5.2",
"angular-material": "1.0.7",
"jquery": "2.2.2"
}
}
Notes:
I used JHipster (generator-jhipster 3.0.0).
In Dev mode everything works good.
These *.css dependents are added automatically by Gulp.
The issue here was that some files do not have an initial comment, so cssnano did not separate it in lines.

Merging two gulp streams

I am trying to merge two gulp sources as follows:
gulp.task("build", ["clean"], function () {
var sb = gulp.src([
paths.bower + "jquery/jquery.js",
paths.bower + "angular/angular.js"
])
.pipe(flatten())
.pipe(gulp.dest(paths.scripts.vnd));
var sm = gulp.src([
paths.scripts.vnd + "jquery.js",
paths.scripts.vnd + "angular.js"
])
.pipe(concat("app.js"))
.pipe(gulp.dest(paths.scripts.dst))
.pipe(rename("app.min.js"))
.pipe(uglify())
.pipe(gulp.dest(paths.scripts.dst));
return merge(sb, sm);
});
Somehow only the first one is executed.
However, if I move the second one to another task with dependency on build then both are executed ...
Am I doing the merging the wrong way?
UPDATE 1
I updated my task to build both LESS files and JS files so I have:
var
gulp = require("gulp"),
fs = require("fs"),
merge = require("merge2"),
concat = require("gulp-concat"),
flatten = require("gulp-flatten"),
less = require('gulp-less'),
minify = require('gulp-minify-css'),
rename = require("gulp-rename"),
rimraf = require("gulp-rimraf"),
uglify = require("gulp-uglify");
var paths = {
bower: "./bower_components/",
scripts: {
app: "./" + "/scripts/app/",
dst: "./" + "/scripts/dst/",
vnd: "./" + "/scripts/vnd/"
},
styles: {
app: "./" + project.webroot + "/styles/app/",
dst: "./" + project.webroot + "/styles/dst/"
}
};
gulp.task("build", function () {
var sbm = gulp.src([
paths.styles.app + "*.less",
paths.styles.vnd + "*.less"
])
.pipe(less())
.pipe(minify())
.pipe(concat("app.css"))
.pipe(gulp.dest(paths.styles.dst))
.pipe(rename("app.min.css"))
.pipe(gulp.dest(paths.styles.dst));
var scb = gulp.src(
[
paths.bower + "jquery/jquery.js",
paths.bower + "angular/angular.js"
])
.pipe(flatten())
.pipe(gulp.dest(paths.scripts.vnd));
var scm = gulp.src(
[
paths.scripts.vnd + "jquery.js",
paths.scripts.vnd + "angular.js"
])
.pipe(concat("app.js"))
.pipe(gulp.dest(paths.scripts.dst))
return merge(sbm, scb, scm);
});
Somehow, this only executes sbm ... Does anyone knows why?
I also tried #topleft's suggestion but when including the LESS tasks at the end the app.min.js file get's the Less code in it ...
try this with merge2 plugin, that's how I do it
var merge = require('merge2');
gulp.task("build", ["clean"], function () {
var sb = gulp.src([
paths.bower + "jquery/jquery.js",
paths.bower + "angular/angular.js"
])
.pipe(flatten())
.pipe(gulp.dest(paths.scripts.vnd));
var sm = gulp.src([
paths.scripts.vnd + "jquery.js",
paths.scripts.vnd + "angular.js"
])
return merge(sb, sm)
.pipe(concat("app.js"))
.pipe(gulp.dest(paths.scripts.dst))
.pipe(rename("app.min.js"))
.pipe(uglify())
.pipe(gulp.dest(paths.scripts.dst));
});
as an example, here is how I merge my two LESS streams : (one is unCSS'ed, the other is not)
/* ===== LESS START ===== */
gulp.task('less', function() {
// Get static styles
var streamMain = gulp.src([
srcAssets + '/less/**/*.less',
srcAssets + '!/less/**/interactive.less',])
// Convert to CSS
.pipe(less())
// Remove unused CSS rules
.pipe(uncss({
html: [dest + '/index.html']
}))
// Get dynamic styles
var streamEvents = gulp.src(srcAssets + '/less/global/interactive.less')
// Convert to CSS
.pipe(less())
// Merge dynamic and static styles
return merge(streamMain, streamEvents)
// Concatenate in a single file
.pipe(concat('main.css'))
// Remove all comments
.pipe(stripCssComments({
all: true
}))
// Autoprefixer for browser compatibility
.pipe(autoprefixer())
// Compression
.pipe(minifyCSS())
// Output file
.pipe(gulp.dest(dest + '/css'));
});
/* ===== LESS END ===== */