Skip to content

Commit

Permalink
Add userfrosting/vite-php-twig
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Jun 29, 2024
1 parent 0238b7a commit c2450c1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 9 deletions.
6 changes: 6 additions & 0 deletions app/config/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
'csrf' => [
'enabled' => false,
],

'vite' => [
'dev' => env('VITE_DEV_ENABLED', true),
'base' => '',
'server' => 'http://[::1]:3000/'
]
];
18 changes: 16 additions & 2 deletions app/src/Demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
namespace UserFrosting\Demo;

use UserFrosting\Sprinkle\Core\Core;
use UserFrosting\Sprinkle\Core\Sprinkle\Recipe\TwigExtensionRecipe;
use UserFrosting\Sprinkle\SprinkleRecipe;
use UserFrosting\ViteTwig\ViteTwigExtension;

class Demo implements SprinkleRecipe
class Demo implements SprinkleRecipe, TwigExtensionRecipe
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -61,6 +63,18 @@ public function getRoutes(): array
*/
public function getServices(): array
{
return [];
return [
Services::class,
];
}

/**
* {@inheritDoc}
*/
public function getTwigExtensions(): array
{
return [
ViteTwigExtension::class,
];
}
}
37 changes: 37 additions & 0 deletions app/src/Services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* UserFrosting Vue Demo (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/demo-vue
* @copyright Copyright (c) 2023 Louis Charette
* @license https://github.com/userfrosting/demo-vue/blob/main/LICENSE.md (MIT License)
*/

namespace UserFrosting\Demo;

use UserFrosting\Config\Config;
use UserFrosting\ServicesProvider\ServicesProviderInterface;
use UserFrosting\UniformResourceLocator\ResourceLocatorInterface;
use UserFrosting\ViteTwig\ViteManifest;
use UserFrosting\ViteTwig\ViteManifestInterface;
use UserFrosting\ViteTwig\ViteTwigExtension;

class Services implements ServicesProviderInterface
{
public function register(): array
{
return [
ViteManifestInterface::class => function (ResourceLocatorInterface $locator, Config $config) {
$manifest = new ViteManifest(
manifestPath: (string) $locator->getResource('public://.vite/manifest.json'),
basePath: $config->getString('vite.base', ''),
devEnabled: $config->getBool('vite.dev', true),
serverUrl: $config->getString('vite.server', ''),
);

return $manifest;
}
];
}
}
11 changes: 5 additions & 6 deletions app/templates/pages/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
{{ encore_entry_link_tags('app') }}
<!-- <link rel="icon" href="favicon.ico"> -->
<title>{{ site.title }}</title>
{# <link rel="stylesheet" href="./assets/main-CNEYaoRK.css"> #}
{# <script type="module" src="http://[::1]:3000/@vite/client"></script> #}
{# {{ encore_entry_link_tags('app') }} #}
{{ vite_css('main.ts') }}
{{ vite_preload('main.ts') }}
</head>
<body>
<noscript>
<strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
{{ encore_entry_script_tags('app') }}
{# <script type="module" src="http://[::1]:3000/main.ts"></script> #}
{# <script type="module" src="./assets/main-CNFAaDZc.js"></script> #}
{# {{ encore_entry_script_tags('app') }} #}
{{ vite_js('main.ts') }}
</body>
</html>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"ext-gd": "*",
"userfrosting/framework": "~5.1.0",
"userfrosting/sprinkle-core": "~5.1.0",
"userfrosting/sprinkle-account": "~5.1.0"
"userfrosting/sprinkle-account": "~5.1.0",
"userfrosting/vite-php-twig": "^1.0.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
Expand Down

0 comments on commit c2450c1

Please sign in to comment.