Skip to content

Commit

Permalink
Merge pull request #19 from s2b/task/release140
Browse files Browse the repository at this point in the history
Task/release140
  • Loading branch information
s2b authored Sep 28, 2023
2 parents 8adc5b5 + 025fb39 commit 0c64c32
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 11 deletions.
3 changes: 1 addition & 2 deletions Classes/Configuration/VitePlaceholderProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 1 addition & 3 deletions Classes/Exception/ViteException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Praetorius\ViteAssetCollector\Exception;

class ViteException extends \Exception
{
}
class ViteException extends \Exception {}
3 changes: 1 addition & 2 deletions Classes/Service/ViteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function __construct(
private readonly FrontendInterface $cache,
protected AssetCollector $assetCollector,
protected PackageManager $packageManager
) {
}
) {}

public function determineDevServer(ServerRequestInterface $request): UriInterface
{
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**

<details>
<summary><i>More Options</i></summary>

Expand Down
8 changes: 8 additions & 0 deletions Resources/Private/ViteConfigTemplates/glob.vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'];

Expand All @@ -32,4 +37,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
8 changes: 8 additions & 0 deletions Resources/Private/ViteConfigTemplates/static.vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -26,4 +31,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -24,4 +29,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -23,4 +28,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -23,4 +28,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'];

Expand All @@ -30,4 +35,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -24,4 +29,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -23,4 +28,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -24,4 +29,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -24,4 +29,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -24,4 +29,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -24,4 +29,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -23,4 +28,7 @@ export default defineConfig({
outDir: resolve(rootPath, VITE_OUTPUT_PATH),
},
publicDir: false,
server: {
origin: VITE_DEV_ORIGIN,
},
});
27 changes: 24 additions & 3 deletions Tests/Functional/Command/ViteConfigCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 0c64c32

Please sign in to comment.