Open geoffatcircle opened 7 years ago
+1 on this issue! Ran into the same thing, but really weird - it used to work before. Have you found a solution already @geoffatcircle ?
I ran into the issue while including .json
files for my data. I tracked the issue down to require cache and solved it using module https://www.npmjs.com/package/clear-require.
Simply do the following in your gulp task before calling fileinclude (or use regex to clear only the files you need)
const clearRequire = require('clear-require');
clearRequire.all();
@geoffatcircle @automagisch
I believe I have a similar issue, but I'm not sure that the solution above is for me. So I could use some additional input. :)
I have HTML files that are made up of included partials. When I save a parent file directly, it gets compiled and shows in the stream as the only changed file (because of since: { lastRun(html) }
). When I save a partial file, the HTML task with fileInclude
runs but nothing happens (nothing in the stream; no visible on-page changes) because I have a glob that ignores partial files so they're not compiled to the destination folder as part of the stream.
The expectation is that I'm able to save a partial file which then triggers the compilation of the parent file(s) that it's associated with (seems like it might be a far-fetched desire), but the only way I'm able to achieve something close to this is by removing since: { lastRun(html) }
from the HTML task (see below). When I do that, all of the parent files are compiled any time I make a change to a parent or partial file, which isn't desired. I don't want a batch of parent files compiling every time I make a change to a single partial. Is this even possible? Thanks in advance!
const {src, dest, lastRun, watch, series} = require('gulp');
const pkg = require('./package.json');
const browsersync = require('browser-sync').create();
const $ = require('gulp-load-plugins') ({
pattern: ['*'],
scope: ['devDependencies']
});
function html() {
return src([
pkg.paths.src.html + '**/*.html', // Captures all parent HTML files
'!' + pkg.paths.src.html + '**/partials/**/*.html' // Ignores all partial HTML files
], {
since: lastRun(html)
})
.pipe($.fileInclude({
prefix: '@@',
basepath: '@file'
}))
.pipe($.cacheBust({
type: 'timestamp'
}))
.pipe(dest(pkg.paths.dist.html))
.pipe(browsersync.stream());
}
function server() {
browsersync.init({
notify: false,
server: pkg.paths.dist.root
});
watch([
pkg.paths.src.html + '**',
pkg.paths.src.html + '**/*.html'
])
.on('add', series(html))
.on('change', series(html))
.on('unlink', function(filepath) {
const srcPath = path.relative(path.resolve(pkg.paths.src.html), filepath);
const destPath = path.resolve(pkg.paths.dist.html, srcPath);
$.del.sync(destPath);
});
}
If I make changes to an included file, save it, and subsequently call fileinclude in a gulp task (from gulp-live-server and watch) the file does not change. I need to stop gulp-live-server and start again.