Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheritance files not processed #5

Closed
djedlajn opened this issue Mar 21, 2017 · 5 comments
Closed

Inheritance files not processed #5

djedlajn opened this issue Mar 21, 2017 · 5 comments

Comments

@djedlajn
Copy link

djedlajn commented Mar 21, 2017

Hi,

Here is my setup, image for your convenience.

2017-03-21

This is after compiling pug to html works as expected its just that changing partial does not trigger change.

2017-03-21 2

Here is the JS file dedicated to compiling pug to html.

gulp.task('pug', function () {
    return gulp.src(config.src) // same as ('./app/**/*.pug')

        //only pass unchanged *main* files and *all* the partials
        .pipe(changed('dist', {
            extension: '.html'
        }))

        //filter out unchanged partials, but it only works when watching
        .pipe(gulpif(global.isWatching, cached('pug')))

        //find files that depend on the files that have changed
        .pipe(pugInheritance({
            basedir: 'app',
            skip: 'node_modules'
        }))

        //filter out partials (folders and files starting with "_" )
        .pipe(filter(function (file) {
            // Added views to exclude folder from building.
            return !/\/_/.test(file.path) && !/^_/.test(file.relative) && !/views/.test(file.relative);
        }))

        //process jade templates
        .pipe(pug({
            pretty: true
        }))

        //save all the files
        .pipe(gulp.dest(config.dest)); // Same as ('./dist/')
});

gulp.task('setWatch', function () {
    global.isWatching = true;
});

I have added views folder to be treated as partials because everything inside is meant to be partial. I did try with _ naming still wont trigger build on compile change.

Here is watch file.


gulp.task('watch', ['setWatch', 'pug'], () => {
    gulp.watch(config.styles, ['styles']); // Same as ('./app/css/**')
    gulp.watch(config.pug, ['pug']); // Same as ('./app/**/*.pug')
});

Here is the config file just in case.

const src = './app'
const dest = './dist'

module.exports = {
    styles: {
        src: `${src}/css/**/*.{sass,scss}`,
        dest: `${dest}/css/`
    },
    pug: {
        src: `${src}/**/*.pug`,
        dest: `${dest}/`
    },
    clean: {
        all: dest,
        styles: `${dest}/css/**`,
        pug: `${dest}/**/.html`
    },
    watch: {
        styles: `${src}/css/**/*.{scss,sass}`,
        pug: `${src}/**/*.pug`
    }
};

It compiles but when i change block pug file it does not trigger compile or detects change whatsoever. What am i missing ? For files to detect change i need to stop watch process delete files from dist run it again and then only it picks up.

Any help would be appreciated.

@pure180
Copy link
Owner

pure180 commented Mar 21, 2017

Can you please add gulb-debug to your task, like in this gulpfile.js and post the result of the terminal?

Please also add a log to gulp-filter, to see the file path that you are filtering on.

...
.pipe(filter(function (file) {
   // Added views to exclude folder from building.
   console.log(file.relative);
   return !/\/_/.test(file.path) && !/^_/.test(file.relative) && !/views/.test(file.relative);
}))
...

@djedlajn
Copy link
Author

djedlajn commented Mar 21, 2017

I think i found what is causing the issue. It is the subtle change in jade/pug api from v1 to v2

In Pug v1, if no file extension is given, .pug is automatically appended to the file name, but in Pug v2 this is behavior is deprecated. Link

It is really subtle, but it appears to have fixed includes not being detected. Will test more and be back with updates.

Edit: For plugin to pickup changes correctly on v2 version of API appending .pug extension to includes is required.

<!DOCTYPE html>
html(lang="en")
// Include needs to have .pug extension !
include views/_block.pug 

body
    .test
        h1

@pure180
Copy link
Owner

pure180 commented Mar 21, 2017

By setting the default file extension, like described in the readme to gulp-pug-inheritance will fix this too. Will close this issue, you can write here if you still facing issues.

@pure180 pure180 closed this as completed Mar 21, 2017
@Grawl
Copy link

Grawl commented May 2, 2017

Have the same issue but with an error:

2017-05-02 14:59 gulp[1416] (FSEvents.framework) FSEventStreamFlushSync(): failed assertion '(SInt64)last_id > 0LL'

It's only on included files.

Root files are compiled one-by-one, as expected.

gulpfile

const $ = gulpLoadPlugins()
const bs = browsersync.create()
gulp.task('views', () => {
	bs.notify('Compiling HTML…', 999999)
    return gulp.src(['app/*.pug', 'app/views/**/*.pug'])
        .pipe($.changed('.tmp', { extension: '.html' }))
        .pipe($.if(global.isWatching, $.cached('pug')))
        .pipe($.pugInheritance({
			basedir: 'app',
			extension: '.pug',
			skip: ['node_modules'],
		}))
		.pipe($.filter(function (file) {
			// Added views to exclude folder from building.
			console.log(file.relative)
			return !/\/_/.test(file.path) && !/^_/.test(file.relative) && !/views/.test(file.relative)
		}))
        .pipe($.pug({ pretty: true }))
        .pipe(gulp.dest('.tmp'))
		.pipe(bs.reload({ stream: true }))
})

gulp.task('serve', () => {
	global.isWatching = true
	runSequence(['clean'], ['views', 'styles', 'scripts'], () => {
		
		gulp.watch(
			[
				'app/**/*.pug',
				'app/includes/**/*',
			],
			['views']
		)
		
	})
})

@Grawl
Copy link

Grawl commented May 2, 2017

Oops looks like my problem is in Node itself: nodejs/node#854

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants