Skip to content

Commit

Permalink
fix: recompile pages after changes in the global data file
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Oct 17, 2024
1 parent a72248a commit 97df4b7
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 134 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## 4.1.1 (2024-10-17)

- fix: after 2-3 changes of the data file (global or entry), the dependent entry template is not recompiled.
- test: add test for Eta preprocessor with default options

## 4.1.0 (2024-09-29)

- feat: add supports the `require` of CommonJS and JSON files in EJS templates:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Advanced alternative to [html-webpack-plugin](https://github.com/jantimon/html-w
- `<img src="@images/pic.png" srcset="@images/pic400.png 1x, @images/pic800.png 2x" />`\
Source files will be resolved, processed and auto-replaced with correct URLs in the bundled output.
- **Inlines** [JS](#recipe-inline-js), [CSS](#recipe-inline-css) and [Images](#recipe-inline-image) into HTML. See [how to inline all resources](#recipe-inline-all-assets-to-html) into single HTML file.
- Recompiles the template after changes in the [data file](#option-entry-data) assigned to the entry page as a JSON or JS filename.
- Generates the [preload](#option-preload) tags for fonts, images, video, scripts, styles.
- Generates the [integrity](#option-integrity) attribute in the `link` and `script` tags.
- Generates the [favicons](#favicons-bundler-plugin) of different sizes for various platforms.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-bundler-webpack-plugin",
"version": "4.1.0",
"version": "4.1.1",
"description": "HTML Bundler Plugin for Webpack renders HTML templates containing source files of scripts, styles, images. Supports template engines: Eta, EJS, Handlebars, Nunjucks, Pug, TwigJS. Alternative to html-webpack-plugin.",
"keywords": [
"html",
Expand Down
40 changes: 40 additions & 0 deletions src/Common/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,44 @@ const filterParentPaths = (paths) =>
return result;
}, []);

/**
* Touch the file.
*
* @param {string} file
* @param {FileSystem} fs The file system. Should be used the improved Webpack FileSystem.
* @return {Promise<unknown>}
*/
const touchAsync = (file, { fs }) => {
return new Promise((resolve, reject) => {
const time = new Date();
fs.utimes(file, time, time, (err) => {
if (err) {
return fs.open(file, 'w', (err, fd) => {
if (err) return reject(err);
fs.close(fd, (err) => (err ? reject(err) : resolve(fd)));
});
}
resolve();
});
});
};

/**
* Touch the file.
*
* @param {string} file
* @param {FileSystem} fs The file system. Should be used the improved Webpack FileSystem.
* @return void
*/
const touch = (file, { fs }) => {
const time = new Date();
try {
fs.utimesSync(file, time, time);
} catch (err) {
fs.closeSync(fs.openSync(file, 'w'));
}
};

module.exports = {
loadModule,
isDir,
Expand All @@ -232,4 +270,6 @@ module.exports = {
relativePathVerbose,
rootSourceDir,
filterParentPaths,
touchAsync,
touch,
};
14 changes: 13 additions & 1 deletion src/Loader/Option.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ class Option {

if (!dataFile) {
const fs = this.fileSystem;
dataFile = path.isAbsolute(dataValue) ? dataValue : path.join(process.cwd(), dataValue);
dataFile = this.resolveFile(dataValue);

if (!fs.existsSync(dataFile)) {
dataFileNotFoundException(dataFile);
}

PluginService.setDataFiles(this.pluginCompiler, dataValue, dataFile);
}

Expand All @@ -288,6 +289,17 @@ class Option {
return data || {};
}

/**
* Resolve relative file path.
*
* @param {string} file
* @return {string}
*/
resolveFile(file) {
const context = this.pluginCompiler.options.context;
return path.isAbsolute(file) ? file : path.join(context, file);
}

/**
* Returns original loader options.
*
Expand Down
Loading

0 comments on commit 97df4b7

Please sign in to comment.