-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
Current behaviour π£
In the index.html I want to include a static JS File (a 3rd party JS file, not bundled with webpack):
index.html
<script src="modernizr.js"></script>
This file should be included before the main JS file (injected by html-webpack-plugin) and should not be defered. It's name should also be unique (hashed).
After build, the dist folder contains:
index.html:
<script src="modernizr.d680fb275258c1e22931.js">
<script defer="defer" src="js/index.0e428668b6b726cf637e.js">
but the generated js file is: modernizr.d14201e2d4a0ec290a14.js
asset modernizr.d14201e2d4a0ec290a14.js 10.5 KiB [emitted] [immutable] [from: modernizr.js] [minimized] 1 related asset
So the filenames do not match (content hashes are different) and the browser returns a 404 error.
When running webpack serve, it seems that the generated hashes are the same.
Expected behaviour βοΈ
After build, the generated filename should match the filename referanced in dist html file.
Reproduction Example πΎ
Use the following code above.
webpack.config.js
...
module: {
rules: {
{
test: /\.html$/i,
loader: "html-loader",
},
{
test: /modernizr\.js$/i,
type: "asset/resource",
generator: {
filename: "[name].[contenthash].js"
},
},
}
}
...
Environment π₯
Node.js v18.15.0
darwin 22.3.0
9.5.0
[email protected] /Users/andreivictor/Work/job-index
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ¬ @webpack-cli/[email protected]
β β βββ [email protected] deduped
β βββ¬ @webpack-cli/[email protected]
β β βββ [email protected] deduped
β βββ¬ @webpack-cli/[email protected]
β β βββ [email protected] deduped
β βββ [email protected] deduped
βββ¬ [email protected]
β βββ¬ [email protected]
β β βββ [email protected] deduped
β βββ [email protected] deduped
βββ¬ [email protected]
βββ¬ [email protected]
βββ [email protected] deduped
[email protected] /Users/andreivictor/Work/job-index
βββ [email protected]