gulp-community / gulp-cached

A simple in-memory file cache for gulp
MIT License
452 stars 23 forks source link

Single entry .less file #15

Closed DeadcatDev closed 8 years ago

DeadcatDev commented 8 years ago

Hi,

i have 'main' index.less file which @import some additional files like

@import a.less @import b.less @import c. less and so...

So i have a gulp watcher

gulp.watch([less folder path *.less], ['styles-frontend']);

on all less files, but my build function is like:

gulp.task('styles-frontend', function() {
    return gulp.src(path.stylesFrontend.src)
        .pipe(cache('styles-frontend'))
        .pipe(sourcemaps.init())
        .pipe(prefixer({
            browsers: ['last 5 versions']
        }))
        .pipe(less({
            errLogToConsole: true,
            plugins: [cleancss]
        }))
        .pipe(cssmin())
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest(path.stylesFrontend.dest))
});

The problem is that gulp-cached 'caching' only the 'index.less' file for it's name and contents, so if i update b.less - the cache will return the same file so nothing will change at all.

Any suggestion to run cache for every file?

yocontra commented 8 years ago

Move cache after less so the contents will change when b.less is changed

DeadcatDev commented 8 years ago

Not working - project have 'tree structure' with one entry root (point), so it must be rebuild from bottom to top every time :(( Probably need refactor and add some gulp-concat to it to use cache. Or maybe you have any idea, now its looks like:

index.less:

@import a.less
@import variables.less
@import c.less

c.less be like:

@import users.less
@import companies.less
@import [...]

and so companies.less be like:

@import invoices.less
@import morethings.less

and so and so.

When i want to rebuild invoices.less from cache there is no variables.less in it so i cant rebuild files like

gulp-task(src[ALL-LESS-FILES->toCSS], fnc(){
allLess.files to manyCss.files and then
concat (them)
minify etc.
}); 

but must do simply

gulp.task(src[index.less],fnc(){
less index -> index.css
minify
});

Thinikn' about doing more flat file structure like

invoices.less:
@import variables.less
@depedencies

for build it separately (from top to bottom) and than -> cache -> concat -> minify -> write.

What you thing about it? Build time is to high for me (like 2sec.) so need cache badly :) Sorry for my engrish ;)

yocontra commented 8 years ago

Probably not the right module for your problem, look at some of the other plugins that handle incremental compilation in gulp