symfony / webpack-encore-bundle

Symfony integration with Webpack Encore!
https://symfony.com/webpack-encore
MIT License
933 stars 83 forks source link

encore_entry_link_tags incorrectly querying manifest.json #230

Open bmorg opened 5 months ago

bmorg commented 5 months ago

I have encountered this while hosting a Symfony app in a subfolder and managed to reproduce it with a minimal test case.

The behavior only shows when framework.assets.strict_mode is set to true.

Error

The error thrown is: Asset "/web-subfolder/app.b75294ae.css" not found in manifest ".../build-output/manifest.json". Did you mean one of these? "my-prefix/app.css", "my-prefix/app.js"

Reproduce

To demonstrate the problem I am setting three different values for these three directories:

manifest.json:

{
  "my-prefix/app.css": "/web-subfolder/app.b75294ae.css",
  "my-prefix/app.js": "/web-subfolder/app.53d71f57.js"
}

entrypoints.json:

{
  "entrypoints": {
    "app": {
      "js": [
        "/web-subfolder/app.53d71f57.js"
      ],
      "css": [
        "/web-subfolder/app.b75294ae.css"
      ]
    }
  }
}

Template:

{{ encore_entry_link_tags('app') }}

Fix

I'm not really sure I completely understand how all the parts work together, but it seems to me that there is no need to call getAssetPath in TagRenderer->renderWebpackLinkTags (here), since the entrypoint already provides the "mapped" values.

Demo

I have created a demo repository here. The relevant changes to reproduce are in this commit.