Skip to content

Commit ac2a23a

Browse files
committed
5564: Use assets mapper for CSS
1 parent 16211ac commit ac2a23a

11 files changed

Lines changed: 157 additions & 10 deletions

File tree

.env

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
COMPOSE_PROJECT_NAME=itksites
2-
#COMPOSE_DOMAIN=itksites.local.itkdev.dk
3-
COMPOSE_DOMAIN=sites.itkdev.dk
2+
COMPOSE_DOMAIN=itksites.local.itkdev.dk
43

54
ITKDEV_TEMPLATE=symfony-6
65

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ phpstan.neon
3434
###> vincentlanglet/twig-cs-fixer ###
3535
/.twig-cs-fixer.cache
3636
###< vincentlanglet/twig-cs-fixer ###
37+
38+
###> symfony/asset-mapper ###
39+
/public/assets/
40+
/assets/vendor/
41+
###< symfony/asset-mapper ###

assets/app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Welcome to your app's main JavaScript file!
3+
*
4+
* This file will be included onto the page via the importmap() Twig function,
5+
* which should already be in your base.html.twig.
6+
*/
7+
import './styles/app.css';
8+
9+
console.log('This log comes from assets/app.js - welcome to AssetMapper! 🎉');

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"phpdocumentor/reflection-docblock": "^5.6.3",
2222
"phpstan/phpdoc-parser": "^2.3",
2323
"symfony/amqp-messenger": "^7.3.2",
24-
"symfony/asset": "^7.3",
24+
"symfony/asset": "7.3.*",
25+
"symfony/asset-mapper": "7.3.*",
2526
"symfony/browser-kit": "^7.3.2",
2627
"symfony/console": "^7.3.4",
2728
"symfony/doctrine-messenger": "^7.3.4",
@@ -41,7 +42,9 @@
4142
"symfony/uid": "^7.3.1",
4243
"symfony/validator": "^7.3.4",
4344
"symfony/webpack-encore-bundle": "^2.3",
44-
"symfony/yaml": "^7.3.3"
45+
"symfony/yaml": "^7.3.3",
46+
"twig/extra-bundle": "^2.12|^3.0",
47+
"twig/twig": "^2.12|^3.0"
4548
},
4649
"require-dev": {
4750
"ergebnis/composer-normalize": "^2.48.2",
@@ -112,7 +115,8 @@
112115
],
113116
"auto-scripts": {
114117
"cache:clear": "symfony-cmd",
115-
"assets:install %PUBLIC_DIR%": "symfony-cmd"
118+
"assets:install %PUBLIC_DIR%": "symfony-cmd",
119+
"importmap:install": "symfony-cmd"
116120
},
117121
"coding-standards-apply": [
118122
"PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix"

composer.lock

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

config/packages/asset_mapper.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
framework:
2+
asset_mapper:
3+
# The paths to make available to the asset mapper.
4+
paths:
5+
- assets/
6+
missing_import_mode: strict
7+
8+
when@prod:
9+
framework:
10+
asset_mapper:
11+
missing_import_mode: warn

importmap.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* Returns the importmap for this application.
5+
*
6+
* - "path" is a path inside the asset mapper system. Use the
7+
* "debug:asset-map" command to see the full list of paths.
8+
*
9+
* - "entrypoint" (JavaScript only) set to true for any module that will
10+
* be used as an "entrypoint" (and passed to the importmap() Twig function).
11+
*
12+
* The "importmap:require" command can be used to add new entries to this file.
13+
*/
14+
return [
15+
'app' => [
16+
'path' => './assets/app.js',
17+
'entrypoint' => true,
18+
],
19+
];

src/Controller/Admin/DashboardController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function index(): Response
5252
public function configureDashboard(): Dashboard
5353
{
5454
return Dashboard::new()
55-
->setTitle('<img src="/img/itk-sites-logo.png" width="170px" alt="ITK sites">')
55+
->setTitle('<img src="/img/itk-sites-logo.png" width="170px" alt="ITK sites logo">')
5656
->setFaviconPath('img/favicon.ico')
5757
->renderContentMaximized();
5858
}
@@ -95,6 +95,6 @@ public function configureCrud(): Crud
9595
#[\Override]
9696
public function configureAssets(): Assets
9797
{
98-
return Assets::new()->addCssFile('css/admin.css');
98+
return parent::configureAssets()->addAssetMapperEntry('app');
9999
}
100100
}

symfony.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,21 @@
316316
"symfony/asset": {
317317
"version": "v6.0.3"
318318
},
319+
"symfony/asset-mapper": {
320+
"version": "7.3",
321+
"recipe": {
322+
"repo": "github.com/symfony/recipes",
323+
"branch": "main",
324+
"version": "6.4",
325+
"ref": "5ad1308aa756d58f999ffbe1540d1189f5d7d14a"
326+
},
327+
"files": [
328+
"assets/app.js",
329+
"assets/styles/app.css",
330+
"config/packages/asset_mapper.yaml",
331+
"importmap.php"
332+
]
333+
},
319334
"symfony/browser-kit": {
320335
"version": "v6.0.3"
321336
},

0 commit comments

Comments
 (0)