Don't scan lazy modules until we know they are actually imported.

This commit is contained in:
Ben Newman
2016-01-08 17:59:55 -05:00
parent 0a6324013a
commit b63d9b7d3d

View File

@@ -76,8 +76,10 @@ export default class ImportScanner {
getOutputFiles() {
this.outputFiles.forEach(file => {
const absPath = pathJoin(this.sourceRoot, file.sourcePath);
file.deps = this._scanDeps(absPath, file.data);
if (! file.lazy || file.imported) {
const absPath = pathJoin(this.sourceRoot, file.sourcePath);
file.deps = this._scanDeps(absPath, file.data);
}
});
return this.outputFiles;
@@ -121,8 +123,22 @@ export default class ImportScanner {
// as imported so we know to include them in the bundle if they
// are lazy.
const index = this.absPathToOutputIndex[absImportedPath];
this.outputFiles[index].imported = true;
return;
const file = this.outputFiles[index];
// Eager files and files that we have imported before do not need
// to be scanned again. Lazy files that we have not imported
// before still need to be scanned, however.
const alreadyScanned = ! file.lazy || file.imported;
// Whether the file is eager or lazy, mark it as imported. For
// lazy files, this makes the difference between being included in
// or omitted from the bundle. For eager files, this just ensures
// we won't scan them again.
file.imported = true;
if (alreadyScanned) {
return;
}
}
if (! this._hasKnownExtension(absImportedPath)) {