Skip to content

Commit

Permalink
fix: added dynamic package assets support also
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh-webkul committed Sep 1, 2023
1 parent 1dce243 commit ab5e7d6
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 76 deletions.
10 changes: 6 additions & 4 deletions config/bagisto-vite.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@

'viters' => [
'admin' => [
'hot_file' => 'admin-default-vite.hot',
'build_directory' => 'themes/admin/default/build',
'hot_file' => 'admin-default-vite.hot',
'build_directory' => 'themes/admin/default/build',
'package_assets_directory' => 'src/Resources/assets',
],

'shop' => [
'hot_file' => 'shop-default-vite.hot',
'build_directory' => 'themes/shop/default/build',
'hot_file' => 'shop-default-vite.hot',
'build_directory' => 'themes/shop/default/build',
'package_assets_directory' => 'src/Resources/assets',
],
],
];
10 changes: 6 additions & 4 deletions config/themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
'views_path' => 'resources/themes/default/views',

'vite' => [
'hot_file' => 'shop-default-vite.hot',
'build_directory' => 'themes/shop/default/build',
'hot_file' => 'shop-default-vite.hot',
'build_directory' => 'themes/shop/default/build',
'package_assets_directory' => 'src/Resources/assets',
],
],
],
Expand All @@ -43,8 +44,9 @@
'views_path' => 'resources/admin-themes/default/views',

'vite' => [
'hot_file' => 'admin-default-vite.hot',
'build_directory' => 'themes/admin/default/build',
'hot_file' => 'admin-default-vite.hot',
'build_directory' => 'themes/admin/default/build',
'package_assets_directory' => 'src/Resources/assets',
],
],
],
Expand Down
9 changes: 4 additions & 5 deletions packages/Webkul/Theme/src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,13 @@ public function url(string $url, ?string $namespace)
{
$url = trim($url, '/');

/**
* Testing vite url, on monitoring.
*/
$viteUrl = 'src/Resources/assets/' . $url;

/**
* If the namespace is null, it means the theming system is activated. We use the request URI to
* detect the theme and provide Vite assets based on the current theme.
*/
if (empty($namespace)) {
$viteUrl = trim($this->vite['package_assets_directory'], '/') . '/' . $url;

return Vite::useHotFile($this->vite['hot_file'])
->useBuildDirectory($this->vite['build_directory'])
->asset($viteUrl);
Expand All @@ -116,6 +113,8 @@ public function url(string $url, ?string $namespace)
throw new ViterNotFound($namespace);
}

$viteUrl = trim($viters[$namespace]['package_assets_directory'], '/') . '/' . $url;

return Vite::useHotFile($viters[$namespace]['hot_file'])
->useBuildDirectory($viters[$namespace]['build_directory'])
->asset($viteUrl);
Expand Down
34 changes: 34 additions & 0 deletions public/themes/admin/default/build/assets/app-43acbb23.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion public/themes/admin/default/build/assets/app-ac3cb3b1.css

This file was deleted.

34 changes: 0 additions & 34 deletions public/themes/admin/default/build/assets/app-b5741f9c.js

This file was deleted.

1 change: 1 addition & 0 deletions public/themes/admin/default/build/assets/app-f927c33e.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/themes/admin/default/build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"src/Resources/assets/css/app.css": {
"file": "assets/app-ac3cb3b1.css",
"file": "assets/app-f927c33e.css",
"isEntry": true,
"src": "src/Resources/assets/css/app.css"
},
Expand Down Expand Up @@ -204,7 +204,7 @@
"css": [
"assets/app-c04ede37.css"
],
"file": "assets/app-b5741f9c.js",
"file": "assets/app-43acbb23.js",
"isEntry": true,
"src": "src/Resources/assets/js/app.js"
},
Expand Down
25 changes: 0 additions & 25 deletions public/themes/shop/default/build/assets/app-458db3b4.js

This file was deleted.

25 changes: 25 additions & 0 deletions public/themes/shop/default/build/assets/app-c15271ae.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/themes/shop/default/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"css": [
"assets/app-f72387a9.css"
],
"file": "assets/app-458db3b4.js",
"file": "assets/app-c15271ae.js",
"isEntry": true,
"src": "src/Resources/assets/js/app.js"
}
Expand Down

0 comments on commit ab5e7d6

Please sign in to comment.