diff --git a/Classes/Configuration/VitePlaceholderProcessor.php b/Classes/Configuration/VitePlaceholderProcessor.php index 7b02971..65634d0 100644 --- a/Classes/Configuration/VitePlaceholderProcessor.php +++ b/Classes/Configuration/VitePlaceholderProcessor.php @@ -26,8 +26,7 @@ final class VitePlaceholderProcessor implements PlaceholderProcessorInterface public function __construct( private readonly ExtensionConfiguration $extensionConfiguration, private readonly ViteService $viteService - ) { - } + ) {} public function canProcess(string $placeholder, array $referenceArray): bool { diff --git a/Classes/Exception/ViteException.php b/Classes/Exception/ViteException.php index 6ab5d99..21fe5c9 100644 --- a/Classes/Exception/ViteException.php +++ b/Classes/Exception/ViteException.php @@ -4,6 +4,4 @@ namespace Praetorius\ViteAssetCollector\Exception; -class ViteException extends \Exception -{ -} +class ViteException extends \Exception {} diff --git a/Classes/Service/ViteService.php b/Classes/Service/ViteService.php index cbcd6f8..ab455e3 100644 --- a/Classes/Service/ViteService.php +++ b/Classes/Service/ViteService.php @@ -22,8 +22,7 @@ public function __construct( private readonly FrontendInterface $cache, protected AssetCollector $assetCollector, protected PackageManager $packageManager - ) { - } + ) {} public function determineDevServer(ServerRequestInterface $request): UriInterface { diff --git a/README.md b/README.md index 10e6b77..fcf971f 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,11 @@ The generated configuration makes sure that vite * generates a `manifest.json` file * outputs assets to a publicly accessible directory +**Note that you might need to set `VITE_DEV_ORIGIN` in the generated config file manually +to the URL of your vite dev server in order to be able to load generated assets (e. g. +font files referenced in a css file) correctly. There will probably be a cleaner solution +in an upcoming version of the extension.** +
More Options diff --git a/Resources/Private/ViteConfigTemplates/glob.vite.config.js b/Resources/Private/ViteConfigTemplates/glob.vite.config.js index 36f878b..0ac16a4 100644 --- a/Resources/Private/ViteConfigTemplates/glob.vite.config.js +++ b/Resources/Private/ViteConfigTemplates/glob.vite.config.js @@ -15,6 +15,11 @@ const VITE_ENTRYPOINTS = [ const VITE_OUTPUT_PATH = 'public/_assets/vite/'; // ------------------------------------------------------ +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + // Ignored patterns to speed up globbing const VITE_PATTERN_IGNORE = ['**/node_modules/**', '**/.git/**']; @@ -32,4 +37,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Resources/Private/ViteConfigTemplates/static.vite.config.js b/Resources/Private/ViteConfigTemplates/static.vite.config.js index f9b311b..4ccee02 100644 --- a/Resources/Private/ViteConfigTemplates/static.vite.config.js +++ b/Resources/Private/ViteConfigTemplates/static.vite.config.js @@ -15,6 +15,11 @@ const VITE_ENTRYPOINTS = [ const VITE_OUTPUT_PATH = 'public/_assets/vite/'; // ------------------------------------------------------ +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -26,4 +31,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/configForExtension.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/configForExtension.vite.config.js index c812d95..67e520b 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/configForExtension.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/configForExtension.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "Resources/Public/Vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointExtensionPath.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointExtensionPath.vite.config.js index 62f944e..d94184a 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointExtensionPath.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointExtensionPath.vite.config.js @@ -12,6 +12,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -23,4 +28,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointFileadmin.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointFileadmin.vite.config.js index 7e07c7c..81e7503 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointFileadmin.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/entrypointFileadmin.vite.config.js @@ -12,6 +12,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -23,4 +28,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/globEntrypoint.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/globEntrypoint.vite.config.js index b4007ca..c95401a 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/globEntrypoint.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/globEntrypoint.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + // Ignored patterns to speed up globbing const VITE_PATTERN_IGNORE = ['**/node_modules/**', '**/.git/**']; @@ -30,4 +35,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/multipleEntrypoints.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/multipleEntrypoints.vite.config.js index 96b5710..421cb1e 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/multipleEntrypoints.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/multipleEntrypoints.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/OutputConfig/withoutEntrypoints.vite.config.js b/Tests/Fixtures/ViteConfigCommand/OutputConfig/withoutEntrypoints.vite.config.js index 17708b3..ccf9adb 100644 --- a/Tests/Fixtures/ViteConfigCommand/OutputConfig/withoutEntrypoints.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/OutputConfig/withoutEntrypoints.vite.config.js @@ -12,6 +12,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -23,4 +28,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/configForExtension.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/configForExtension.vite.config.js index 3f022d1..3289c26 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/configForExtension.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/configForExtension.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "Resources/Public/Vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inExtensionRoot.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inExtensionRoot.vite.config.js index dd152bf..1195afa 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inExtensionRoot.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inExtensionRoot.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inNonExistingSubfolder.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inNonExistingSubfolder.vite.config.js index 7553a3c..81926ac 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inNonExistingSubfolder.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inNonExistingSubfolder.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRoot.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRoot.vite.config.js index 4b2595b..848c1ff 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRoot.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRoot.vite.config.js @@ -13,6 +13,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -24,4 +29,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRootBeforeOverwrite.vite.config.js b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRootBeforeOverwrite.vite.config.js index 17708b3..ccf9adb 100644 --- a/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRootBeforeOverwrite.vite.config.js +++ b/Tests/Fixtures/ViteConfigCommand/WriteConfigToFile/inProjectRootBeforeOverwrite.vite.config.js @@ -12,6 +12,11 @@ const VITE_ENTRYPOINTS = [ // Output path for generated assets const VITE_OUTPUT_PATH = "public/_assets/vite/"; +// Base URL that will be prepended to all referenced assets in dev mode +// Set this to the URL of your vite dev server, +// e. g. https://myproject.ddev.site:5173 +const VITE_DEV_ORIGIN = ''; + const rootPath = resolve(__dirname, VITE_TYPO3_ROOT); export default defineConfig({ base: '', @@ -23,4 +28,7 @@ export default defineConfig({ outDir: resolve(rootPath, VITE_OUTPUT_PATH), }, publicDir: false, + server: { + origin: VITE_DEV_ORIGIN, + }, }); diff --git a/Tests/Functional/Command/ViteConfigCommandTest.php b/Tests/Functional/Command/ViteConfigCommandTest.php index 161910c..5b25d9e 100644 --- a/Tests/Functional/Command/ViteConfigCommandTest.php +++ b/Tests/Functional/Command/ViteConfigCommandTest.php @@ -33,6 +33,15 @@ public function setUp(): void } } + public function tearDown(): void + { + // Delete config file from overwriteConfigFile() test + $overwriteConfigFile = self::getInstancePath() . '/vite.config.js'; + if (file_exists($overwriteConfigFile)) { + unlink($overwriteConfigFile); + } + } + public static function outputConfigDataProvider(): array { return [ @@ -255,7 +264,11 @@ public function overwriteConfigFile(): void $input = ['--outputfile' => './vite.config.js']; $output = new BufferedOutput(); $command->run(new ArrayInput($input, $command->getDefinition()), $output); - self::assertEquals(sprintf("Vite config has been written to %s.\n", $outputFile), $output->fetch()); + self::assertEquals( + sprintf("Vite config has been written to %s.\n", $outputFile), + $output->fetch(), + 'Initial file can be written' + ); self::assertEquals( $expectedFirstResult, file_get_contents($outputFile), @@ -268,7 +281,11 @@ public function overwriteConfigFile(): void ]; $output = new BufferedOutput(); $command->run(new ArrayInput($input, $command->getDefinition()), $output); - self::assertEquals(sprintf("Output file %s already exists. Use --force if you want to overwrite the existing file.\n", $outputFile), $output->fetch()); + self::assertEquals( + sprintf("Output file %s already exists. Use --force if you want to overwrite the existing file.\n", $outputFile), + $output->fetch(), + 'Overwrite attempt without force option' + ); self::assertEquals( $expectedFirstResult, file_get_contents($outputFile), @@ -278,7 +295,11 @@ public function overwriteConfigFile(): void $input['--force'] = null; $output = new BufferedOutput(); $command->run(new ArrayInput($input, $command->getDefinition()), $output); - self::assertEquals(sprintf("Vite config has been written to %s.\n", $outputFile), $output->fetch()); + self::assertEquals( + sprintf("Vite config has been written to %s.\n", $outputFile), + $output->fetch(), + 'Overwrite attempt with force option' + ); self::assertEquals( $expectedLaterResult, file_get_contents($outputFile), diff --git a/ext_emconf.php b/ext_emconf.php index 0b3c3be..e38c615 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -7,7 +7,7 @@ 'author' => 'Simon Praetorius', 'author_email' => 'simon@praetorius.me', 'state' => 'stable', - 'version' => '1.3.0', + 'version' => '1.4.0', 'constraints' => [ 'depends' => [ 'typo3' => '11.5.0-12.4.99',