Elixir gulp versioning - allow rev-manifest.js merges instead of ovewrites - laravel

I am attempting a way to run gulp for every page separately.
Every page has its gulp file and you can gulp for a page only with $ gulp --file=name
These gulpfiles are stored under /gulp So my main gulpfile.js has the following:
require('./gulp/elixir-extensions');
var args = require("yargs");
var file = args.argv.file;
if(file){
var path = './gulp/'+file;
require('./gulp/'+file);
}
else{
console.log('Pass the file: gulp --file:name');
}
So in my /gulp directory I have gulpfile extensions for every page on my site. home.js, about.js, contact.js, login.js etc..
Typically - home.js
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix
/**
* Combine home scripts
*/
.scripts(...)
/**
* Combine home CSS files
*/
.styles(...)
/**
* Remove unused css selectors
*/
.uncss(...)
/**
* Remove redundant/repeated css declarations
*/
.purge(...)
/**
* Apply version control
*/
.version([
"public/css/home.css",
"public/js/home.js",
]);
});
and my gulp/elixir-extensions.js :
const gulp = require('gulp');
const Elixir = require('laravel-elixir');
const Task = Elixir.Task;
const uncss = require('gulp-uncss');
const purge = require('gulp-css-purge');
const rename = require('gulp-rename');
Elixir.extend('uncss', function(file, link, out, renamed) {
new Task('uncss', function() {
return gulp.src(file)
.pipe(uncss({
html: [link]
}))
.pipe(rename(renamed))
.pipe(gulp.dest(out));
});
});
Elixir.extend('purge', function(css, out, renamed) {
new Task('purge', function() {
return gulp.src(css)
.pipe(purge())
.pipe(rename(renamed))
.pipe(gulp.dest(out));
});
});
My problem is that the public/build/rev-manifest.js gets ovewritten every time I gulp for a single page.
rev-manifest.js after $ gulp --file=home
{
"css/home.css": "css/home-0a3d3926fc.css",
"js/home.js": "js/home-6df29810e8.js"
}
rev-manifest.js after $ gulp --file=about
{
"css/about.css": "css/about-fc0a5d3926.css",
"js/about.js": "js/about-f0921ds0e8.js"
}
How can I merge every revision like the following?
{
"css/home.css": "css/home-0a3d3926fc.css",
"js/home.js": "js/home-6df29810e8.js",
"css/about.css": "css/about-fc0a5d3926.css",
"js/about.js": "js/about-f0921ds0e8.js"
}

Figured out a solution - do all the versioning in the main gulpfile.js.
This way, every page gets its assets only versioned (but not compiled) every time.
require('./gulp/elixir-extensions');
var elixir = require('laravel-elixir');
var args = require("yargs");
var file = args.argv.file;
if(file){
var filepath = './gulp/'+file;
require('./gulp/'+file);
elixir(function(mix) {
mix
/**
* Apply version control to all assets
*/
.version([
"public/css/auth.css",
"public/css/backend.css",
"public/js/backend.js",
"public/css/home.css",
"public/js/home.js",
"public/css/about.css",
"public/js/about.js",
])
// .phpUnit()
// .compressHtml()
});
}
else{
console.log('Pass the file: gulp --file:name');
}

Related

Laravel Mix BrowserSync It is not triggered

According to the Laravel Mix documents. I'm using Webpack to compile styles and launch BrowserSync in the process.
This is my complete webpack.mix.js document. You can see browserSync on line 92:
require('laravel-mix-merge-manifest');
const fs = require('fs');
const mix = require('laravel-mix');
const pathEnv = 'resources/sass/_enviroments/' + process.env.NODE_ENV;
const sites = [
'RP-ES',
'TZ-ES',
'CAL-ES',
'RUP-ES',
'FL-ES',
'SP-ES',
'WPX-IT',
'WPX-UK',
'WPX-CH',
'WPX-FR',
'WPX-DE',
'WPX-PT',
'WPX-NL',
'MTN-ES',
'MTN-DE',
'MTN-FR'
];
const tmpFiles = [];
try
{
if (process.env.NODE_ENV == 'development')
{
if (!process.env.hasOwnProperty('npm_config_only_css'))
generateJS();
if (!process.env.hasOwnProperty('npm_config_only_js'))
{
if (!process.env.hasOwnProperty('npm_config_site'))
{
// throw('In development, parameter "--site" is mandatory, one of the follow values: "'+sites.join('", "')+'"');
sites.forEach(slug=>{
generateSiteCss(slug)
});
}
else
generateSiteCss(process.env.npm_config_site);
}
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
mix.webpackConfig({plugins: [new BundleAnalyzerPlugin()]});
}
else
{
generateJS();
sites.forEach(slug=>{
generateSiteCss(slug)
});
}
mix.version()
mix.mergeManifest()
mix.then(deleteTmpFiles);
}
catch(e)
{
deleteTmpFiles();
throw e;
}
function generateJS()
{
console.log('Generating JS...');
// app scripts (common in all pages)
mix.js('resources/js/app.js', 'public/js')
.extract()
// individual scripts (auto register) to use alone en certain pages
.js('resources/js/components/helpcenter_results.vue.js', 'public/js/vue_components') // used in helpcenter
.js('resources/js/components/newsletter.vue.js', 'public/js/vue_components') // used in home
.js('resources/js/components/slick_carousel.vue.js', 'public/js/vue_components') // used in product pages & designs list
.js('resources/js/components/vue_tab.vue.js', 'public/js/vue_components') // used in login
// combined components with auto register included
.js('resources/js/products_page.js', 'public/js')
.js('resources/js/checkout.js', 'public/js')
.js('resources/js/payment_methods.js', 'public/js')
.js('resources/js/cart.js', 'public/js')
.js('resources/js/products_list.js', 'public/js')
.js('resources/js/accounts.js', 'public/js')
// required libs that are used in certain pages and are not available througth npm
.copyDirectory('resources/js/libs','public/js/libs')
.copyDirectory('resources/fonts','public/fonts')
.copyDirectory('resources/css','public/css')
.browserSync('regalospersonales.local');
}
function generateSiteCss(slug)
{
console.log('Generating CSS for the site: '+ slug +'...');
let pathSite = `resources/sass/_sites/${slug}`;
let outputPath = `public/css/sites/${slug}`;
let tmpPath = `resources/sass/${slug}`;
let includePaths = [
pathEnv,
pathSite
];
fs.writeFileSync(`${tmpPath}_common.scss`, `#import '_common';`);
fs.writeFileSync(`${tmpPath}_helpcenter.scss`, `#import '_helpcenter';`);
tmpFiles.push(`${tmpPath}_common.scss`);
tmpFiles.push(`${tmpPath}_helpcenter.scss`);
mix.sass(`${tmpPath}_common.scss`, `${outputPath}/common.css`, { includePaths: includePaths })
.sass(`${tmpPath}_helpcenter.scss`, `${outputPath}/helpcenter.css`, { includePaths: includePaths })
//.then(deleteTmpFiles)
//console.log(result);
//throw new Exception('asdfasdf');
}
function deleteTmpFiles(){
console.log('Deleting temporal files...');
tmpFiles.forEach(f=>{
if (fs.existsSync(f))
fs.unlinkSync(f);
});
}
And of course I have sync browser installed with my package.json:
"devDependencies": {
"browser-sync": "^2.26.7",
"browser-sync-webpack-plugin": "^2.0.1",
Everything looks good. But when I execute:
npm run watch
All my styles and javascript are compiled, watch is activated but it doesn't say anything about BrowserSync.
No error or anything happens, it's like BrowserSync is ignored.
What's going on?

How to add jekyll build command in gulp watch task?

I need to run jekyll build during gulp watch task and I did that as per the following code.
var gulp = require('gulp-help')(require('gulp')),
sass = require('gulp-sass');
gulp.task('sass', function(){
return gulp.src(sassFiles)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(cssDest));
});
gulp.task('jekyll-build', function (done) {
return cp.spawn(jekyll, ['build'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('default', ['sass'], function(){
gulp.watch(['_includes/**/*.js', '_includes/**/*._', 'assets/styles/**/*.scss'], ['jekyll-build', 'sass']);
});
When I make some changes in any file and try to save at once, command runs in terminal but it is not getting reflected in UI. I need to save twice or thrice to get the changes reflected. Not sure what's the issue or whether its the issue of the gulp watch code added here. Any help is appreciated.
When you say the changes are not reflected do you mean the browser is not refreshing?
The line to launch jekyll build is different for mac vs Windows, your looks like it is for a Mac, on Windows I use jekyll.bat on this line (jekyll, ['build'].
In your watch step you are not watching very much. Rather than try to tell gulp to watch every different thing I do the opposite and tell gulp to watch everything **/*.* and then tell it what not to watch like !_site/**/*. This also lets you watch the config file for changes.
Also, it doesn't look like you are live-reloading with browser sync, that is half the fun of using gulp with jekyll (other half is having gulp do sass processing as it is much faster than jekyll).
Here is a gulp file that I use and a link to a write up I did about it:
https://rdyar.github.io/2017/10/01/speed-up-jekyll-by-using-gulp-for-sass-and-other-assets/
var gulp = require('gulp');
var browserSync = require('browser-sync');
var cp = require('child_process');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
var cssnano = require('cssnano');
var imagemin = require('gulp-imagemin');
var htmlhint = require("gulp-htmlhint");
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
// Gulp as asset manager for jekyll. Please note that the assets folder is never cleaned
//so you might want to manually delete the _site/assets folder once in a while.
// this is because gulp will move files from the assets directory to _site/assets,
// but it will not remove them from _site/assets if you remove them from assets.
/**
* Build the Jekyll Site - for windos. If you are on a Mac/linux change jekyll.bat to just jekyll
*/
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll.bat', ['build'], {stdio: 'inherit'})
.on('close', done);
});
/**
* Rebuild Jekyll & do page reload when watched files change
*/
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('serve', ['jekyll-build'], function() {
browserSync.init({
server: "_site/"
});
});
/**
* Watch jekyll source files for changes, don't watch assets
*/
gulp.task('watch', function () {
gulp.watch(['**/*.*', '!_site/**/*','!_assets/**/*','!node_modules/**/*','!.sass-cache/**/*' ], ['jekyll-rebuild']);
});
//watch just the sass files - no need to rebuild jekyll
gulp.task('watch-sass', ['sass-rebuild'], function() {
gulp.watch(['_assets/sass/**/*.scss'], ['sass-rebuild']);
});
// watch just the js files
gulp.task('watch-js', ['js-rebuild'], function() {
gulp.watch(['_assets/js/**/*.js'], ['js-rebuild']);
});
// watch just the image files
gulp.task('watch-images', ['images-rebuild'], function() {
gulp.watch(['_assets/img/**/*.*'], ['images-rebuild']);
});
//if sass files change just rebuild them with gulp-sass and what not
gulp.task('sass-rebuild', function() {
var plugins = [
autoprefixer({browsers: ['last 2 version']}),
cssnano()
];
return gulp.src('_assets/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.init())
.pipe(postcss(plugins))
.pipe(sourcemaps.write('.'))
.pipe( gulp.dest('_site/assets/css/') )
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('js-rebuild', function(cb) {
return gulp.src('_assets/js/**/*.js')
.pipe(uglify())
.pipe( gulp.dest('_site/assets/js/') )
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('images-rebuild', function(cb) {
return gulp.src('_assets/img/**/*.*')
.pipe( gulp.dest('_site/assets/img/') )
.pipe(browserSync.reload({
stream: true
}))
});
/**
* Default task, running just `gulp` will
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['serve', 'watch','watch-sass','watch-js','watch-images']);
//build and deploy stuff
gulp.task('imagemin', function() {
console.log('Minimizing images in source!!');
return gulp.src('_assets/img/**/*')
.pipe(imagemin())
.pipe(gulp.dest(function (file) {
return file.base;
}));
});
gulp.task('w3', function() {
gulp.src("_site/**/*.html")
.pipe(htmlhint())
.pipe(htmlhint.reporter())
})
// validate from the command line instead, works better
// npm install htmlhint -g
// htmlhint _site/**/*.html

ASP.Net Core + Angular 2 + SystemJS: typescript transpilation

I am using Visual Studio 2015 Update 3 to create a ASP.Net core application that runs an angular 2 application. I am using SystemJs for configuration that I picked from one of the sites and it has this line of code with the comment.
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'typescript',
I understand the reason for the comment. My application is currently slow.
I'd like to know what are the other options available to ensure that the transpilation does not happen in the browser? How do I pre-transpile the code and load directly from the output location?
This usually means that ts files are sent to browser and transpiled there instead of happening on server side and js code to be sent and executed on client side.
Since you are using gulp you can create a task to transpile the typescript files and bundle them. You can use "gulp-typescript": "^2.5.0" package to achieve this.
However you need to setup your config first (I've just copy pasted the config from their repo):
'use strict';
var GulpConfig = (function () {
function gulpConfig() {
//Got tired of scrolling through all the comments so removed them
//Don't hurt me AC :-)
this.source = './src/';
this.sourceApp = this.source + 'app/';
this.tsOutputPath = this.source + '/js';
this.allJavaScript = [this.source + '/js/**/*.js'];
this.allTypeScript = this.sourceApp + '/**/*.ts';
this.typings = './typings/';
this.libraryTypeScriptDefinitions = './typings/main/**/*.ts';
}
return gulpConfig;
})();
module.exports = GulpConfig;
Then you need to setup the tasks, easiest way just to copy paste the already setup tasks from their repo again:
'use strict';
var gulp = require('gulp'),
debug = require('gulp-debug'),
inject = require('gulp-inject'),
tsc = require('gulp-typescript'),
tslint = require('gulp-tslint'),
sourcemaps = require('gulp-sourcemaps'),
del = require('del'),
Config = require('./gulpfile.config'),
tsProject = tsc.createProject('tsconfig.json'),
browserSync = require('browser-sync'),
superstatic = require( 'superstatic' );
var config = new Config();
/**
* Generates the app.d.ts references file dynamically from all application *.ts files.
*/
// gulp.task('gen-ts-refs', function () {
// var target = gulp.src(config.appTypeScriptReferences);
// var sources = gulp.src([config.allTypeScript], {read: false});
// return target.pipe(inject(sources, {
// starttag: '//{',
// endtag: '//}',
// transform: function (filepath) {
// return '/// <reference path="../..' + filepath + '" />';
// }
// })).pipe(gulp.dest(config.typings));
// });
/**
* Lint all custom TypeScript files.
*/
gulp.task('ts-lint', function () {
return gulp.src(config.allTypeScript).pipe(tslint()).pipe(tslint.report('prose'));
});
/**
* Compile TypeScript and include references to library and app .d.ts files.
*/
gulp.task('compile-ts', function () {
var sourceTsFiles = [config.allTypeScript, //path to typescript files
config.libraryTypeScriptDefinitions]; //reference to library .d.ts files
var tsResult = gulp.src(sourceTsFiles)
.pipe(sourcemaps.init())
.pipe(tsc(tsProject));
tsResult.dts.pipe(gulp.dest(config.tsOutputPath));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.tsOutputPath));
});
/**
* Remove all generated JavaScript files from TypeScript compilation.
*/
gulp.task('clean-ts', function (cb) {
var typeScriptGenFiles = [
config.tsOutputPath +'/**/*.js', // path to all JS files auto gen'd by editor
config.tsOutputPath +'/**/*.js.map', // path to all sourcemap files auto gen'd by editor
'!' + config.tsOutputPath + '/lib'
];
// delete the files
del(typeScriptGenFiles, cb);
});
gulp.task('watch', function() {
gulp.watch([config.allTypeScript], ['ts-lint', 'compile-ts']);
});
gulp.task('serve', ['compile-ts', 'watch'], function() {
process.stdout.write('Starting browserSync and superstatic...\n');
browserSync({
port: 3000,
files: ['index.html', '**/*.js'],
injectChanges: true,
logFileChanges: false,
logLevel: 'silent',
logPrefix: 'angularin20typescript',
notify: true,
reloadDelay: 0,
server: {
baseDir: './src',
middleware: superstatic({ debug: false})
}
});
});
gulp.task('default', ['ts-lint', 'compile-ts']);
This creates the following Gulp tasks:
gen-ts-refs: Adds all of your TypeScript file paths into a file named typescriptApp.d.ts. This file will be used to support code help in some editors as well as aid with compilation of TypeScript files.
ts-lint: Runs a “linting” task to ensure that your code follows specific guidelines defined in the tsline.js file (you can skip this if you like).
compile-ts: Compiles TypeScript to JavaScript and generates source map files used for debugging TypeScript code in browsers such as Chrome.
clean-ts: Used to remove all generated JavaScript files and source map files.
watch: Watches the folder where your TypeScript code lives and triggers the ts-lint, compile-ts, and gen-ts-refs tasks as files changes are detected.
default: The default Grunt task that will trigger the other tasks to run. This task can be run by typing gulp at the command-line when you’re within the typescriptDemo folder.
Note:
You need to change the folders based your file structure but the gist of it is that you need those TypeScript files to be compiled and sent to browser as plain JavaScript.

Reload plugin when using `jekyll serve`

I'm developing a Jekyll plugin. When I run the jekyll serve command, site files are regenerated when I change any markdown, html, or plugin files, as expected. The problem I've found is that while markdown/HTML files are regenerated, the plugins themselves are not reloaded. I have to terminate jekyll serve and issue the command again for the plugin changes to go into effect. Is there a way to make it so that the plugins get reloaded automatically when changed?
This is for Jekyll 3.1.2.
Based on the suggestion from #DavidJacquel and the gist I found here, I used Gulp with this gulpfile
'use strict';
var gulp = require('gulp'),
express = require('express'),
spawn = require('child_process').spawn;
var jekyll_file = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
gulp.task('jekyll', () => {
var jekyll = spawn(jekyll_file, ['build', '--incremental']);
var output = '';
jekyll.stdout.on('data', (t) => { output += t; });
jekyll.stderr.on('data', (t) => { output += t; });
jekyll.on('exit', (code) => {
if (code)
console.log(`Jekyll exited with code: ${code}\n${output}`);
else
console.log("Finished Jekyll build");
});
});
gulp.task('serve', () => {
var server = express();
server.use(express.static('_site/'));
server.listen(4000);
});
gulp.task('watch', () => {
gulp.watch(['**/*.html', '**/*.md', '_plugins/*.rb', '!_site/**/*'], ['jekyll']);
});
gulp.task('default', ['jekyll', 'serve', 'watch']);
to get the desired effect. Also created issue here.

Gulp Sass not compiling partials

So I am using Gulp Sass with gulp-changed (i've also tried gulp-newer with the updated syntax changes) and watching all the scss files in my folders.
When I change a base scss file it will compile without any problems.
However if I change a partial it won't compile the sass file that has a dependency on that partial.
Gulp
var SRC = './stylesheets/**/*.scss';
var DEST = './stylesheets';
gulp.task('sass', function() {
return gulp.src(SRC)
.pipe(changed(DEST, { extension: '.css' }))
.pipe(plumber({
errorHandler: handleErrors
}))
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: [
'C:/var/www/mobile 2/stylesheets'
]}))
.pipe(sourcemaps.write('./'))
.on('error', handleErrors)
.pipe(gulp.dest(DEST))
});
Folders
├── scss
│ └── base.scss
│ ├── _partial1.scss
│ └── _partial2.scss
│ └── anotherBase.scss
│ ├── _anotherBasePartial1.scss
│ └── _anotherBasePartial2.scss
Making changes to base.scss || anotherBase.scss changes made, making changes to partial1.scss nothing.
As you can see in the log:
[15:14:02] Starting 'sass'... //here i changed _partial1.scss
[15:14:03] Finished 'sass' after 248 ms
[15:18:20] Starting 'sass'...
[15:18:20] Finished 'sass' after 289 ms
[BS] File changed: c:\var\www\mobile 2\stylesheets\sitescss\responsive\tools\base.css
[15:18:24] Starting 'sass'...
[15:18:24] Finished 'sass' after 289 ms
[BS] File changed: c:\var\www\mobile 2\stylesheets\sitescss\responsive\tools\anotherBase.css
I would like it to compile the scss whenever a partial is changed.
A bit late for the show, but if I understand you right; you want to run your build when you change ANY scss file, whether that being a partial or not, right? (but not including the partials in the build itself – as that is handled by sass #import).
I normally use this approach:
var scss_source = [ 'path/to/scss' ],
partials_source = [ 'path/to/partials' ];
gulp.task('scss', function () {
gulp.src( scss_source )
...
});
var scss_watcher = gulp.watch([ scss_source, partials_source ], [ 'scss' ]);
I pass only the scss_source to the build, but BOTH sources to the watcher. That way I can seperate all partials from the rest of the scss sources, but have changes to any of the files trigger a build. And I don't have to include yet another module for handling this.
I usually keep my partials in separate directories (think shared, and not mixed with other scss files).
Hope this makes sense in your case – otherwise I do apologize.
try
var SRC = './stylesheets/**/{*.scss,_*.scss}';
if partials lay in the same folder or a subfolder.
https://www.npmjs.com/package/gulp-changed
By default it's only able to detect whether files in the stream
changed.
I'm guessing you probably want this: https://github.com/floatdrop/gulp-watch
This might have more to do with how you're including the partials than anything else - have your #imported the partials into your base sass file?
i.e., does base.scss have
#import 'partial1';
#import 'partial2';
Somewhere in there?
EDIT
Okay I just ran into a similar issue, I ended up just using gulp-newer + looping through an array to generate the gulp tasks. So it looked something like
var sassMain = ['base', 'anotherBase'];
sassMain.forEach(current, function() {
var src = current + '.scss';
return gulp.src(src)
.pipe(newer(destination)
.pipe(plumber())
.pipe(sass())
.pipe(gulp.dest(destination))
});
Not really the most flexible thing in the world (especially with nested directories for the base url), but kind of gets where you want to be. gulp-cached also almost gets where you want to be without this trickery, but has the same won't-compile-partials issue.
I use https://github.com/vigetlabs/gulp-starter as a template with https://github.com/berstend/gulp-sass-inheritance
It works but only with 2 levels of deep
var gulp = require('gulp');
var debug = require('gulp-debug');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var handleErrors = require('../lib/handleErrors');
var autoprefixer = require('gulp-autoprefixer');
var path = require('path');
var cached = require('gulp-cached');
var sassInheritance = require('gulp-sass-inheritance');
var gulpif = require('gulp-if');
var filter = require('gulp-filter');
var duration = require('gulp-duration');
var notify = require('gulp-notify');
var paths = {
src : 'app/styles',
dest: 'grails-app/assets'
}
var isPartial = function (file) {
return /_/.test(file.relative);
}
//set global.isWatching = true on gulp watch
gulp.task('css', function () {
return gulp.src(paths.src)
//.pipe(debug({title: 'before cache:'}))
.pipe(gulpif(global.isWatching, cached('sass')))
//.pipe(gulpif(global.isWatching, debug({title: 'after cache:'})))
.pipe(gulpif(isPartial, sassInheritance({dir: path.join(config.root.src, config.tasks.css.src), debug: false}).on('error', handleErrors))) //,
.pipe(debug({title: 'after sassInheritance:'}))
//.pipe(debug({title: 'after filter:'}))
.pipe(sourcemaps.init())
.pipe(sass()).on('error', handleErrors)
.pipe(debug({title: 'after sass:'}))
//.pipe(notify('Sass compiled <%= file.relative %>'))
.pipe(autoprefixer(config.tasks.css.autoprefixer))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.dest))
//.pipe(duration('after sass'))
.pipe(debug({title: 'before browserSync:'}))
.pipe(browserSync.reload({stream: true}))
})
This is an excellent question. I had faced this problem and get rid of that after a huge amount of time. Because there was no such things I found online at that time to get rid of that.
sass
abstracts
_base.scss
base
components
layout
pages
themes
vendors
main.scss
main.scss
#import 'sass/abstracts/base';
const gulp = require('gulp');
const sass = require('gulp-sass');
const rename = require('gulp-rename');
const browserSync = require('browser-sync');
const gulpSequence = require('gulp-sequence');
const sassInheritance = require('gulp-sass-inheritance');
const filter = require('gulp-filter');
var cached = require('gulp-cached');
var gulpif = require('gulp-if');
gulp.task('sass', function() {
return gulp.src('sass/main.scss')
//filter out unchanged scss files, only works when watching
.pipe(gulpif(global.isWatching, cached('sass')))
//find files that depend on the files that have changed
.pipe(sassInheritance({dir: 'sass'}))
.pipe(filter(function (file) {
return !/\//.test(file.path) || !/^_/.test(file.relative);
}))
.pipe(sass())
.pipe(rename('style.compile.css'))
.pipe(gulp.dest('css/'))
.pipe(browserSync.stream());
})
gulp.task('serve', ['sass'], function () {
browserSync.init(
{
server: "./"
}
);
gulp.watch('sass/abstracts/**/*.scss', ['sass']);;
gulp.watch('index.html').on('change', browserSync.reload);
});
Run gulp serve.

Resources