Skip to content

Commit fef1fa4

Browse files
committed
fix: output URL for preloaded resources if publicPath is a URL or root path, #141
1 parent 13168f6 commit fef1fa4

31 files changed

Lines changed: 304 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 4.12.3 (2025-01-18)
4+
5+
- fix: output URL for preloaded resources if publicPath is a URL or root path, #141
6+
37
## 4.12.2 (2025-01-13)
48

59
- fix: allow to define the `renderStage` option lower than `PROCESS_ASSETS_STAGE_SUMMARIZE`, #137

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ The possible values:
702702
- `publicPath: '//cdn.example.com/'` - an external URL with the same protocol (`http://` or `https://`)
703703
- `publicPath: 'https://cdn.example.com/'` - an external URL with the `https://` protocol only
704704

705+
> [!WARNING]
706+
>
707+
> If an incorrect value is specified you'll receive 404 errors while loading these resources.
708+
705709
<a id="webpack-option-output-filename" name="webpack-options-output-filename"></a>
706710

707711
### `output.filename`

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "4.12.2",
3+
"version": "4.12.3",
44
"description": "Generates complete single-page or multi-page website from source assets. Build-in support for Markdown, Eta, EJS, Handlebars, Nunjucks, Pug. Alternative to html-webpack-plugin.",
55
"keywords": [
66
"html",
@@ -146,7 +146,7 @@
146146
},
147147
"dependencies": {
148148
"@types/html-minifier-terser": "^7.0.2",
149-
"ansis": "3.6.0",
149+
"ansis": "3.9.0",
150150
"enhanced-resolve": ">=5.7.0",
151151
"eta": "^3.5.0",
152152
"html-minifier-terser": "^7.2.0"

src/Plugin/Preload.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,21 @@ class Preload {
6161
}
6262

6363
/**
64-
*
6564
* @param {AssetEntryOptions} entry The entry where is specified the resource.
6665
* @param {FileInfo|null} issuer The issuer file info.
6766
* @param {string} assetFile The asset output filename.
6867
* @return {string}
6968
*/
7069
getPreloadFile(entry, issuer, assetFile) {
71-
if (issuer && issuer.resource !== entry.resource) {
70+
if (
71+
(this.pluginOption.autoPublicPath || this.pluginOption.isRelativePublicPath) &&
72+
issuer &&
73+
issuer.resource !== entry.resource
74+
) {
7275
// recovery preload output file of an asset relative by entry point
7376
const issuerDir = path.dirname(issuer.filename);
7477
const webRootPath = path.posix.join(issuerDir, assetFile);
78+
7579
assetFile = this.pluginOption.getAssetOutputFile(webRootPath, entry.filename);
7680
}
7781

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><script src="js/file1.034defc3.js"></script><script src="js/file2.e5c7f644.js"></script><script src="js/file3.f1b372d2.js"></script><script src="js/file4.daa27ac4.js"></script><script src="js/file5.c863871f.js"></script><script src="js/cli.250af678.js"></script><script src="js/index.ca3dc62f.js"></script></head><body><h1>Hello World!</h1></body></html>
1+
<!DOCTYPE html><html><head><script src="js/file1.034defc3.js"></script><script src="js/file2.e5c7f644.js"></script><script src="js/file3.f1b372d2.js"></script><script src="js/file4.daa27ac4.js"></script><script src="js/file5.c863871f.js"></script><script src="js/cli.242bd8e6.js"></script><script src="js/index.1222a4ca.js"></script></head><body><h1>Hello World!</h1></body></html>

test/cases/_pug/require-script-tags/expected/js/cli.242bd8e6.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/_pug/require-script-tags/expected/js/cli.250af678.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/cases/_pug/require-script-tags/expected/js/index.1222a4ca.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cases/_pug/require-script-tags/expected/js/index.ca3dc62f.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)