Symfony 7, Zweig, AssetMapper: Vermögenswerte werden bei Dev gut, aber 404 in Prod
Posted: 06 Apr 2025, 21:04
Ich versuche naiv, AssetMapper zu lernen und die Anweisungen zu befolgen, aber ich muss etwas falsch machen. In meiner lokalen Entwicklungsumgebung funktioniert es einwandfrei. In der Umgebung von prod auf dem Server, die ich für die Produktion verwenden möchte, habe ich PHP Bin/Console Asset-Map ausgeführt: Kompilieren Sie gemäß der Dokumentation:
Aber wenn ich die Seite im Browser anzeige, sind die CSS und JS- und Bildanlagen 404. Betrachten Sie die von der Twig -Funktion {{asset ('Bilder/logo.png')} , wir sehen, dass dieses SRC auf einen versionierten Asset:
Die Datei gibt es also, die Berechtigungen sind in Ordnung, aber sie sind 404. Alle meine Vermögenswerte werden gut serviert. Das gleiche IMG -Tag sieht so aus: < /p>
curl -s https://127.0.0.1:8001/ | grep logo
Aber wenn ich im Dateisystem danach suche, aus dem Projektstammordner: < /p>
ls -l public/assets/images/logo-8d825ecbf2f8333f26db08855677ec8a.png
ls: cannot access 'public/assets/images/logo-8d825ecbf2f8333f26db08855677ec8a.png': No such file or directory
[/code]
Und in der Tat gibt es im öffentlichen Ordner nichts außer INDEX.php. /> Wie kann das sein? Ich frage mich, ob es mit Apache und den Umschreibegeln zu tun hat, die ich wörtim aus dem Symfony Apache Pack kopiert und in meine VHOST -Konfiguration eingebaut habe. Aber ich habe diese oder sehr ähnlichen Umschreiberregeln seit Jahren mit anderen Frameworks und Anwendungen verwendet und hatte dieses Problem nie. Ich bin also wirklich ratlos.
Hier ist, was auf meinem Projekt -Unterverzeichnis ...
$ ls
$ tree public
Code: Select all
php bin/console asset-map:compile
// Compiling and writing asset files to public
// Compiled 14 assets
// Manifest written to public/assets/manifest.json
// Import map data written to public/assets/importmap.json.
// Entrypoint metadata written for 1 entrypoints (app).
Die Datei gibt es also, die Berechtigungen sind in Ordnung, aber sie sind 404. Alle meine Vermögenswerte werden gut serviert. Das gleiche IMG -Tag sieht so aus: < /p>
curl -s https://127.0.0.1:8001/ | grep logo
Aber wenn ich im Dateisystem danach suche, aus dem Projektstammordner: < /p>
ls -l public/assets/images/logo-8d825ecbf2f8333f26db08855677ec8a.png
ls: cannot access 'public/assets/images/logo-8d825ecbf2f8333f26db08855677ec8a.png': No such file or directory
[/code]
Und in der Tat gibt es im öffentlichen Ordner nichts außer INDEX.php. /> Wie kann das sein? Ich frage mich, ob es mit Apache und den Umschreibegeln zu tun hat, die ich wörtim aus dem Symfony Apache Pack kopiert und in meine VHOST -Konfiguration eingebaut habe. Aber ich habe diese oder sehr ähnlichen Umschreiberregeln seit Jahren mit anderen Frameworks und Anwendungen verwendet und hatte dieses Problem nie. Ich bin also wirklich ratlos.
Code: Select all
Default configuration for extension with alias: "framework" at path "asset_mapper"
Asset Mapper configuration
asset_mapper:
enabled: true
# Directories that hold assets that should be in the mapper. Can be a simple array of an array of ["path/to/assets": "namespace"]
paths:
# Example:
# - assets/
# Prototype
namespace: ~
# Array of glob patterns of asset file paths that should not be in the asset mapper
excluded_patterns: []
# Examples:
# - '*/assets/build/*'
# - '*/*_.scss'
# If true, any files starting with "." will be excluded from the asset mapper
exclude_dotfiles: true
# If true, a "dev server" will return the assets from the public directory (true in "debug" mode only by default)
server: false
# The public path where the assets will be written to (and served from when "server" is true)
public_prefix: /assets/
# Behavior if an asset cannot be found when imported from JavaScript or CSS files - e.g. "import './non-existent.js'". "strict" means an exception is thrown, "warn" means a warning is logged, "ignore" means the import is left as-is.
missing_import_mode: warn # One of "strict"; "warn"; "ignore"
# Key-value pair of file extensions set to their mime type.
extensions:
# Example:
# .zip: application/zip
# Prototype
extension: ~
# The path of the importmap.php file.
importmap_path: '%kernel.project_dir%/importmap.php'
# The importmap name that will be used to load the polyfill. Set to false to disable.
importmap_polyfill: es-module-shims
# Key-value pair of attributes to add to script tags output for the importmap.
importmap_script_attributes:
# Example:
# data-turbo-track: reload
# Prototype
key: ~
# The directory to store JavaScript vendors.
vendor_dir: '%kernel.project_dir%/assets/vendor'
< /code>
Update Nr. 2: Hier ist die Ausgabe von Debug: Asset-Mapper < /p>
php bin/console debug:asset-map
Asset Mapper Paths
------------------
-------------------------------------------- --------------------------
Path Namespace prefix
-------------------------------------------- --------------------------
vendor/symfony/ux-turbo/assets/dist @symfony/ux-turbo
vendor/symfony/stimulus-bundle/assets/dist @symfony/stimulus-bundle
assets
-------------------------------------------- --------------------------
Mapped Assets
-------------
---------------------------------------------- ----------------------------------------------------
Logical Path Filesystem Path
---------------------------------------------- ----------------------------------------------------
@symfony/ux-turbo/turbo_controller.js vendor/symfony/ux-turbo...ist/turbo_controller.js
@symfony/ux-turbo/turbo_stream_controller.js vendor/symfony/ux-turbo...bo_stream_controller.js
@symfony/stimulus-bundle/controllers.js vendor/symfony/stimulus...ets/dist/controllers.js
@symfony/stimulus-bundle/loader.js vendor/symfony/stimulus...e/assets/dist/loader.js
controllers/hello_controller.js assets/controllers/hello_controller.js
styles/app.css assets/styles/app.css
vendor/bootstrap/bootstrap.index.js assets/vendor/bootstrap/bootstrap.index.js
vendor/bootstrap/dist/css/bootstrap.min.css assets/vendor/bootstrap/dist/css/bootstrap.min.css
vendor/@hotwired/turbo/turbo.index.js assets/vendor/@hotwired/turbo/turbo.index.js
vendor/@hotwired/stimulus/stimulus.index.js assets/vendor/@hotwired/stimulus/stimulus.index.js
vendor/@popperjs/core/core.index.js assets/vendor/@popperjs/core/core.index.js
images/logo.png assets/images/logo.png
bootstrap.js assets/bootstrap.js
app.js assets/app.js
---------------------------------------------- ----------------------------------------------------
$ ls
Code: Select all
assets compose.override.yaml composer.lock config migrations public src templates translations vendor
bin composer.json compose.yaml importmap.php phpunit.xml.dist README.md symfony.lock tests var
Code: Select all
public
├── assets
│ ├── app-1ea1bfab4c9767d2a37f5882af74daad.js
│ ├── bootstrap-64a4b5ea7dbc6734045c3664743a2a98.js
│ ├── controllers
│ │ └── hello_controller-55882fcad241d2bea50276ea485583bc.js
│ ├── entrypoint.app.json
│ ├── images
│ │ └── logo-8d825ecbf2f8333f26db08855677ec8a.png
│ ├── importmap.json
│ ├── manifest.json
│ ├── styles
│ │ └── app-0e8df34d09573e7dc37a853248b222c3.css
│ ├── @symfony
│ │ ├── stimulus-bundle
│ │ │ ├── controllers-20d1514fd94d72a9c2d52e553862ddfb.js
│ │ │ └── loader-e1ee9ace0562f2e6a52301e4ccc8627d.js
│ │ └── ux-turbo
│ │ ├── turbo_controller-ce5e32dafdec0b7752f02e3e2cb25751.js
│ │ └── turbo_stream_controller-a9d0d06c48318d35cc0e0aa27ef6b2dc.js
│ └── vendor
│ ├── bootstrap
│ │ ├── bootstrap.index-c0423c99f6075e6b1cef7579b5c00d32.js
│ │ └── dist
│ │ └── css
│ │ └── bootstrap.min-1712f0378f8675ca7cd423d6262fcccf.css
│ ├── @hotwired
│ │ ├── stimulus
│ │ │ └── stimulus.index-b5b1d00e42695b8959b4a1e94e3bc92a.js
│ │ └── turbo
│ │ └── turbo.index-810f44ef1a202a441e4866b7a4c72d11.js
│ └── @popperjs
│ └── core
│ └── core.index-ceb5b6c0f9e1d3f6c78ef733facfdcda.js
├── index.php
└── test.html