Я наивно пытаюсь изучить AssetMapper и следовать инструкциям, но, должно быть, делаю что-то не так. В моей локальной среде разработки он работает безупречно. В среде prod на сервере, который я планирую использовать для производства, я запустил php bin/console assets-map:compile согласно документации:
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).
но когда я просматриваю страницу в браузере, ресурсы css, js и изображения имеют код 404. Глядя на изображение img, отображаемое функцией Twig, {{ assets('images/logo. png') }}, мы видим этот атрибут src, указывающий на версионный ресурс:
src="/assets/images/logo-8d825ecbf2f8333f26db08855677ec8a.png"
и это ошибка 404. Но когда я ищу файл по этому пути в файловой системе, он оказывается прямо здесь:
ls -l public/assets/images/
-rw-r--r-- 1 david david 151251 Jun 5 16:05 logo-8d825ecbf2f8333f26db08855677ec8a.png
Итак, файл есть, разрешения в порядке, но он 404.
Сравните с машиной разработчика, на которой я запускаю сервер разработки Symfony. . Все мои активы обслуживаются нормально. Тот же тег img выглядит так:
curl -s https://127.0.0.1:8001/ | grep logo
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'
ОБНОВЛЕНИЕ №2: вот выходные данные debug:asset-mapper
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[/b]
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
$-дерево общедоступное
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
Подробнее здесь: https://stackoverflow.com/questions/785 ... 04-in-prod
Symfony 7, Twig, AssetMapper: ресурсы обслуживаются нормально в разработке, но 404 в рабочей версии ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Rails 7 с картами импорта и объединением CSS: ресурсы не обслуживаются из каталога /builds
Anonymous » » в форуме CSS - 0 Ответы
- 24 Просмотры
-
Последнее сообщение Anonymous
-