diff --git a/.gitignore b/.gitignore index ff84ae9b3..95850d695 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,4 @@ js_dist /assets/vendor/ drivers chromedriver.log +/htdocs/dist diff --git a/Makefile b/Makefile index 139032672..7eb411d83 100644 --- a/Makefile +++ b/Makefile @@ -128,6 +128,7 @@ phpstan: ### Compiler les assets pour la production assets: ./node_modules/.bin/webpack -p + php bin/console importmap:install ### Lancer le watcher pour les assets watch: diff --git a/app/config/packages/asset_mapper.yaml b/app/config/packages/asset_mapper.yaml index 9f34e3da2..1c3088ee7 100644 --- a/app/config/packages/asset_mapper.yaml +++ b/app/config/packages/asset_mapper.yaml @@ -5,6 +5,8 @@ framework: - '%kernel.project_dir%/../assets/' importmap_path: '%kernel.project_dir%/../importmap.php' missing_import_mode: strict + vendor_dir: '%kernel.project_dir%/../assets/vendor' + public_prefix: /dist/ when@prod: framework: diff --git a/app/config/services.yml b/app/config/services.yml index 1442a37c4..f64f3e681 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -240,3 +240,12 @@ services: autowire: true arguments: $transports: !tagged_iterator app.social_network.transport + + asset_mapper.local_public_assets_filesystem: + class: AppBundle\AssetMapper\PostCompilationCopyHandler + autowire: true + + asset_mapper.compiled_asset_mapper_config_reader: + class: Symfony\Component\AssetMapper\CompiledAssetMapperConfigReader + arguments: + $directory: '%kernel.project_dir%/../htdocs/dist' diff --git a/htdocs/.htaccess b/htdocs/.htaccess index 826d47b0e..53003f440 100644 --- a/htdocs/.htaccess +++ b/htdocs/.htaccess @@ -54,4 +54,6 @@ RewriteRule ^ask/forum/? https://event.afup.org [R=301,L] RewriteRule ^ask/? / [R=301,L] ## This url are handled by symfony +RewriteCond %{ENV:APP_ENV} ^(dev|test)$ +RewriteRule (dist)/? /index.php [L] # Asset in local development RewriteRule (event|connect|_|association|talks|meetups|blog|admin|p|home|news|techno_watch|member|login|logout|password-reset|rss.xml)/? /index.php [END] diff --git a/importmap.php b/importmap.php index 70ebf14f0..f58317fa6 100644 --- a/importmap.php +++ b/importmap.php @@ -16,4 +16,11 @@ 'path' => './assets/app.js', 'entrypoint' => true, ], + 'semantic-ui/dist/semantic.min.css' => [ + 'version' => '2.5.0', + 'type' => 'css' + ], + 'semantic-ui/dist/semantic.min.js' => [ + 'version' => '2.5.0' + ], ]; diff --git a/sources/AppBundle/AssetMapper/PostCompilationCopyHandler.php b/sources/AppBundle/AssetMapper/PostCompilationCopyHandler.php new file mode 100644 index 000000000..8c3454aa4 --- /dev/null +++ b/sources/AppBundle/AssetMapper/PostCompilationCopyHandler.php @@ -0,0 +1,64 @@ +filesystem = new Filesystem(); + } + + public function write(string $path, string $contents): void + { + $targetPath = $this->publicDir . '/' . ltrim($path, '/'); + + $this->filesystem->dumpFile($targetPath, $contents); + $this->compress($targetPath); + } + + public function copy(string $originPath, string $path): void + { + $targetPath = $this->publicDir . '/' . ltrim($path, '/'); + + $this->filesystem->copy($originPath, $targetPath, true); + $this->compress($targetPath); + } + + public function getDestinationPath(): string + { + return $this->publicDir; + } + + private function compress(string $targetPath): void + { + foreach ($this->extensionsToCompress as $ext) { + if (!str_ends_with($targetPath, ".$ext")) { + continue; + } + + $this->compressor?->compress($targetPath); + + return; + } + } +} diff --git a/templates/admin/base_with_header.html.twig b/templates/admin/base_with_header.html.twig index 8d1803bf4..21e7fe8af 100644 --- a/templates/admin/base_with_header.html.twig +++ b/templates/admin/base_with_header.html.twig @@ -4,7 +4,7 @@ Administration AFUP - + @@ -133,7 +133,7 @@ {% block javascript %} - + diff --git a/templates/base.html.twig b/templates/base.html.twig index 47e16a5c0..c34fd2608 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -58,6 +58,6 @@ {% block footer '' %} {% block javascripts '' %} -{# {% block importmap %}{{ importmap('app') }}{% endblock %}#} + {% block importmap %}{{ importmap('app') }}{% endblock %}