Skip to content
Permalink
Browse files

fix(bundler): avoid unnecessary rewrite of index.html

closes #1049
  • Loading branch information...
huochunpeng committed Feb 16, 2019
1 parent 8e775b7 commit 9faea2f6fef07b7c0f39176a048bc3581969d1a1
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/build/bundle.js
@@ -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);

0 comments on commit 9faea2f

Please sign in to comment.
You can’t perform that action at this time.