Skip to content

Commit

Permalink
fix(bundler): avoid unnecessary rewrite of index.html
Browse files Browse the repository at this point in the history
closes #1049
  • Loading branch information
3cp committed Feb 16, 2019
1 parent 8e775b7 commit 9faea2f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,18 @@ exports.Bundle = class {
return;
}

let indexFile = fs.readFileSync(platform.index);
const indexFile = fs.readFileSync(platform.index);
const outputDir = platform.baseUrl || platform.output;
const configMatcher = Utils.createSrcFileRegex(outputDir, this.moduleId);
const bundleFileName = this.hash ? Utils.generateHashedPath(this.config.name, this.hash) : this.config.name;
const bundleLocation = path.posix.join(outputDir, bundleFileName);
// Replace file name with hashed file name
if (configMatcher.test(indexFile)) {
indexFile = indexFile.replace(configMatcher, 'src="$2' + bundleLocation + '"');
await fs.writeFile(platform.index, indexFile);
logger.info(`Updated file name for ${this.moduleId} in ${platform.index}`);
const newIndexFile = indexFile.replace(configMatcher, 'src="$2' + bundleLocation + '"');
if (newIndexFile !== indexFile) {
await fs.writeFile(platform.index, newIndexFile);
logger.info(`Updated file name for ${bundleFileName} in ${platform.index}`);
}
}
} catch (error) {
logger.error(`Couldn't update file name with revision in ${platform.index}`, error);
Expand Down

0 comments on commit 9faea2f

Please sign in to comment.