Skip to content

Commit 39beb3e

Browse files
committed
optimize vite
1 parent 6914472 commit 39beb3e

File tree

98 files changed

+141
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+141
-69
lines changed

app/Console/Commands/clientAssetGenerator.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function handle()
3232

3333
$vars['xshop-background'] = $gfxes['background'] ?? '#000000';
3434
$vars['xshop-primary'] = $gfxes['primary'] ?? '#6e0000';
35-
$vars['xshop-diff'] = getGrayscaleTextColor($gfxes['primary']) ?? '#6e0000';
36-
$vars['xshop-diff2'] = getGrayscaleTextColor($gfxes['secondary']) ?? '#6e0000';
35+
$vars['xshop-diff'] = getGrayscaleTextColor($gfxes['primary']) ?? '#6e0000';
36+
$vars['xshop-diff2'] = getGrayscaleTextColor($gfxes['secondary']) ?? '#6e0000';
3737
$vars['xshop-secondary'] = $gfxes['secondary'] ?? '#ff0000';
3838
$vars['xshop-text'] = $gfxes['text'] ?? '#111111';
3939
$vars['xshop-border-radius'] = $gfxes['border-radius'] ?? '7px';
@@ -43,21 +43,23 @@ public function handle()
4343
// prepare client.scss and add gfx variable
4444
$js = "// PLEASE DO NOT EDIT THIS FILE, \n// IF YOU WANT ADD ANY CODE CREATE NEW JS INTO client-custom \n import axios from 'axios'; \n window.axios = axios; \n \n window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';" . PHP_EOL;
4545
$variables = "// PLEASE DO NOT EDIT THIS FILE, \n// IF YOU WANT ADD ANY CODE CREATE NEW SCSS INTO client-custom" . PHP_EOL;
46+
$appVariables = '';
4647
foreach ($vars as $k => $var) {
47-
$variables .= '$'."$k:$var;" . PHP_EOL;
48+
$appVariables .= '$' . "$k:$var;" . PHP_EOL;
4849
}
49-
$variables .= ":root{" . PHP_EOL;
50+
$appVariables .= ":root{" . PHP_EOL;
5051
foreach ($vars as $k => $var) {
51-
$variables .= "--$k:$var;" . PHP_EOL;
52+
$appVariables .= "--$k:$var;" . PHP_EOL;
5253
}
53-
$variables .= "}" . PHP_EOL . PHP_EOL;
54+
$appVariables .= "}" . PHP_EOL . PHP_EOL;
5455

56+
file_put_contents(resource_path() . '/sass/client-custom/_app_variables.scss', $appVariables);
5557
// add custom scss and js
5658
$files = File::allFiles(resource_path() . '/sass/client-custom');
5759

5860
foreach ($files as $file) {
5961
if ($file->getType() == 'file' && $file->getExtension() == 'scss') {
60-
$variables .= '@import "client-custom/' .
62+
$variables .= '@use "client-custom/' .
6163
substr(trim($file->getBasename(), '_'), 0, -5)
6264
. '";' . PHP_EOL;
6365
}
@@ -74,18 +76,28 @@ public function handle()
7476
}
7577
// add parts scss & js
7678
foreach (Part::distinct()->get() as $part) {
77-
if (filesize(__DIR__.'/../../../resources/views/segments/' . $part->segment . '/' . $part->part .'/' . $part->part . '.scss' ) > 10) {
78-
$variables .= '@import "../views/segments/' . $part->segment . '/'
79+
if (filesize(__DIR__ . '/../../../resources/views/segments/' . $part->segment . '/' . $part->part . '/' . $part->part . '.scss') > 10) {
80+
$variables .= '@use "../views/segments/' . $part->segment . '/'
7981
. $part->part . '/' . $part->part . '";' . PHP_EOL;
8082
}
81-
if (filesize(__DIR__.'/../../../resources/views/segments/' . $part->segment . '/' . $part->part .'/' . $part->part . '.js' ) > 10){
83+
if (filesize(__DIR__ . '/../../../resources/views/segments/' . $part->segment . '/' . $part->part . '/' . $part->part . '.js') > 10) {
8284
$js .= 'import "../views/segments/' . $part->segment . '/'
8385
. $part->part . '/' . $part->part . '.js";' . PHP_EOL;
8486
}
8587
}
8688

8789
// save scss
88-
file_put_contents(resource_path() . '/sass/client.scss', $variables);
89-
file_put_contents(resource_path() . '/js/client.js', $js);
90+
file_put_contents(resource_path() . '/sass/client.scss', $this->removeDuplicateLines($variables));
91+
file_put_contents(resource_path() . '/js/client.js', $this->removeDuplicateLines( $js ));
92+
}
93+
94+
95+
// remove duplicate lines
96+
private function removeDuplicateLines($text)
97+
{
98+
$lines = explode("\n", $text);
99+
$uniqueLines = array_unique($lines);
100+
$uniqueText = implode("\n", $uniqueLines);
101+
return $uniqueText;
90102
}
91103
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"laravel-vite-plugin": "^1.0",
1515
"sass": "^1.56.1",
1616
"vite": "^5.0",
17-
"vue": "^3.2.37"
17+
"vue": "^3.2.37",
18+
"path": "^0.12.7"
1819
},
1920
"dependencies": {
2021
"bs5-lightbox": "^1.8.3",
12 KB

0 commit comments

Comments
 (0)