Skip to content

Commit 97df4b7

Browse files
committed
fix: recompile pages after changes in the global data file
1 parent a72248a commit 97df4b7

File tree

21 files changed

+350
-134
lines changed

21 files changed

+350
-134
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change log
22

3+
## 4.1.1 (2024-10-17)
4+
5+
- fix: after 2-3 changes of the data file (global or entry), the dependent entry template is not recompiled.
6+
- test: add test for Eta preprocessor with default options
7+
38
## 4.1.0 (2024-09-29)
49

510
- feat: add supports the `require` of CommonJS and JSON files in EJS templates:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Advanced alternative to [html-webpack-plugin](https://github.com/jantimon/html-w
4343
- `<img src="@images/pic.png" srcset="@images/pic400.png 1x, @images/pic800.png 2x" />`\
4444
Source files will be resolved, processed and auto-replaced with correct URLs in the bundled output.
4545
- **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.
46+
- Recompiles the template after changes in the [data file](#option-entry-data) assigned to the entry page as a JSON or JS filename.
4647
- Generates the [preload](#option-preload) tags for fonts, images, video, scripts, styles.
4748
- Generates the [integrity](#option-integrity) attribute in the `link` and `script` tags.
4849
- Generates the [favicons](#favicons-bundler-plugin) of different sizes for various platforms.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"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.",
55
"keywords": [
66
"html",

src/Common/FileUtils.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,44 @@ const filterParentPaths = (paths) =>
224224
return result;
225225
}, []);
226226

227+
/**
228+
* Touch the file.
229+
*
230+
* @param {string} file
231+
* @param {FileSystem} fs The file system. Should be used the improved Webpack FileSystem.
232+
* @return {Promise<unknown>}
233+
*/
234+
const touchAsync = (file, { fs }) => {
235+
return new Promise((resolve, reject) => {
236+
const time = new Date();
237+
fs.utimes(file, time, time, (err) => {
238+
if (err) {
239+
return fs.open(file, 'w', (err, fd) => {
240+
if (err) return reject(err);
241+
fs.close(fd, (err) => (err ? reject(err) : resolve(fd)));
242+
});
243+
}
244+
resolve();
245+
});
246+
});
247+
};
248+
249+
/**
250+
* Touch the file.
251+
*
252+
* @param {string} file
253+
* @param {FileSystem} fs The file system. Should be used the improved Webpack FileSystem.
254+
* @return void
255+
*/
256+
const touch = (file, { fs }) => {
257+
const time = new Date();
258+
try {
259+
fs.utimesSync(file, time, time);
260+
} catch (err) {
261+
fs.closeSync(fs.openSync(file, 'w'));
262+
}
263+
};
264+
227265
module.exports = {
228266
loadModule,
229267
isDir,
@@ -232,4 +270,6 @@ module.exports = {
232270
relativePathVerbose,
233271
rootSourceDir,
234272
filterParentPaths,
273+
touchAsync,
274+
touch,
235275
};

src/Loader/Option.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,12 @@ class Option {
270270

271271
if (!dataFile) {
272272
const fs = this.fileSystem;
273-
dataFile = path.isAbsolute(dataValue) ? dataValue : path.join(process.cwd(), dataValue);
273+
dataFile = this.resolveFile(dataValue);
274274

275275
if (!fs.existsSync(dataFile)) {
276276
dataFileNotFoundException(dataFile);
277277
}
278+
278279
PluginService.setDataFiles(this.pluginCompiler, dataValue, dataFile);
279280
}
280281

@@ -288,6 +289,17 @@ class Option {
288289
return data || {};
289290
}
290291

292+
/**
293+
* Resolve relative file path.
294+
*
295+
* @param {string} file
296+
* @return {string}
297+
*/
298+
resolveFile(file) {
299+
const context = this.pluginCompiler.options.context;
300+
return path.isAbsolute(file) ? file : path.join(context, file);
301+
}
302+
291303
/**
292304
* Returns original loader options.
293305
*

0 commit comments

Comments
 (0)