Skip to content

Cache sass graph and make build faster #22

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var sassGraph = require('sass-graph');
var PLUGIN_NAME = 'gulp-sass-inheritance';

var stream;
var graphObj = {};

function gulpSassInheritance(options) {
options = options || {};
Expand All @@ -16,6 +17,7 @@ function gulpSassInheritance(options) {
}

var files = [];
var graph;

function writeStream(currentFile) {
if (currentFile && currentFile.contents.length) {
Expand All @@ -36,31 +38,35 @@ function gulpSassInheritance(options) {
var stream = this;
if (files.length) {
var allPaths = _.map(files, 'path');
var graph = sassGraph.parseDir(options.dir, options);
if(!graphObj[options.dir]) {
graphObj[options.dir] = sassGraph.parseDir(options.dir, options);
}
graph = graphObj[options.dir];
var newFiles = files;
_.forEach(files, function(file) {
if (graph.index && graph.index[file.path]) {
var fullpaths = recureOnImports([],graph, file.path);

fullpaths.forEach(function (path) {
if (!_.includes(allPaths, path)) {
allPaths.push(path);
newFiles.push(new gutil.File({
cwd: file.cwd,
base: file.base,
path: path,
stat: fs.statSync(path),
contents: fs.readFileSync(path)
}));
}
});
if(!graph.index) {
graph.index = {}
}
graph.addFile(file.path);
var fullpaths = recureOnImports([],graph, file.path);

if (options.debug) {
console.log('File', file.path);
console.log(' - importedBy', fullpaths);
fullpaths.forEach(function (path) {
if (!_.includes(allPaths, path)) {
allPaths.push(path);
newFiles.push(new gutil.File({
cwd: file.cwd,
base: file.base,
path: path,
stat: fs.statSync(path),
contents: fs.readFileSync(path)
}));
}
}
});

if (options.debug) {
console.log('File', file.path);
console.log(' - importedBy', fullpaths);
}
});
es.readArray(files)
.pipe(es.through(
Expand All @@ -70,7 +76,7 @@ function gulpSassInheritance(options) {
function () {
stream.emit('end');
}
));
));
} else {
stream.emit('end');
}
Expand Down