Skip to content

Commit bce32ef

Browse files
committed
HP-1883: massive assets refactoring
1 parent abd8d45 commit bce32ef

16 files changed

+75
-79
lines changed

config/assets.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
Yii::setAlias('@bower', '@vendor/bower-asset');
6+
Yii::setAlias('@npm', '@vendor/npm-asset');
7+
Yii::setAlias('@webroot', dirname(__DIR__, 4) . '/public');
8+
Yii::setAlias('@web', '/');
9+
10+
return [
11+
// Adjust command/callback for JavaScript files compressing:
12+
'jsCompressor' => 'java -jar core/lib/closure-compiler-v20240317.jar --js {from} --js_output_file {to}',
13+
// Adjust command/callback for CSS files compressing:
14+
'cssCompressor' => 'java -jar core/lib/yuicompressor-2.4.8.jar --type css {from} -o {to}',
15+
// Whether to delete asset source after compression:
16+
'deleteSource' => false,
17+
// The list of asset bundles to compress:
18+
'bundles' => [
19+
\hipanel\assets\AppAsset::class,
20+
\hiqdev\themes\adminlte\MainAsset::class,
21+
],
22+
// Asset bundle for compression output:
23+
'targets' => [
24+
'all' => [
25+
'class' => yii\web\AssetBundle::class,
26+
'basePath' => '@webroot/assets',
27+
'baseUrl' => '@web/assets',
28+
'js' => 'all-{hash}.min.js',
29+
'css' => 'all-{hash}.min.css',
30+
],
31+
],
32+
// Asset manager configuration:
33+
'assetManager' => [
34+
'basePath' => '@webroot/assets',
35+
'baseUrl' => '@web/assets',
36+
],
37+
];

config/common.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
99
*/
1010

11+
/** @var array $params */
12+
1113
return [
1214
'aliases' => [
1315
'@organization' => $params['organization.url'],
@@ -78,7 +80,6 @@
7880
],
7981
'container' => [
8082
'singletons' => [
81-
\yii\bootstrap\BootstrapAsset::class => \hipanel\assets\BootstrapAsset::class,
8283
\Psr\Container\ContainerInterface::class => function (\yii\di\Container $container) {
8384
return new class($container) implements \Psr\Container\ContainerInterface {
8485
/**

config/web.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
99
*/
1010

11+
/** @var array $params */
12+
1113
return [
1214
'id' => 'hipanel',
1315
'name' => 'HiPanel',
@@ -108,6 +110,9 @@
108110
'$themedViewPaths' => [dirname(__DIR__) . '/src/views'],
109111
],
110112
],
113+
'assetManager' => [
114+
'bundles' => YII_ENV === 'prod' ? require(dirname(__DIR__, 4) . '/runtime/assets-prod.php') : [],
115+
],
111116
'fileStorage' => [
112117
'class' => \hipanel\components\FileStorage::class,
113118
'secret' => $params['fileStorageSecret'],
@@ -118,13 +123,6 @@
118123
'themeSettingsStorage' => [
119124
'class' => \hipanel\components\ThemeSettingsStorage::class,
120125
],
121-
'assetManager' => [
122-
'bundles' => [
123-
\omnilight\assets\MomentAsset::class => [
124-
'class' => \hipanel\assets\MomentAsset::class,
125-
],
126-
],
127-
],
128126
],
129127
'container' => [
130128
'definitions' => [

lib/closure-compiler-v20240317.jar

13.3 MB
Binary file not shown.

lib/yuicompressor-2.4.8.jar

769 KB
Binary file not shown.

src/assets/AppAsset.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
namespace hipanel\assets;
1212

13-
use hiqdev\assets\select2_bootstrap3_css\Select2Bootstrap3CssAsset;
13+
use hiqdev\assets\pnotify\PNotifyAsset;
14+
use hiqdev\yii2\assets\select2\Select2Asset;
15+
use hiqdev\yii2\reminder\ReminderTopAsset;
16+
use yii\bootstrap\BootstrapAsset;
17+
use yii\bootstrap\BootstrapPluginAsset;
1418
use yii\web\AssetBundle;
1519
use yii\web\YiiAsset;
1620

@@ -26,10 +30,14 @@ class AppAsset extends AssetBundle
2630
public $depends = [
2731
YiiAsset::class,
2832
BootstrapAsset::class,
33+
BootstrapPluginAsset::class,
2934
FontAwesome::class,
3035
LessSpaceAsset::class,
31-
Select2Bootstrap3CssAsset::class,
36+
Select2Asset::class,
3237
HipanelAsset::class,
3338
CondensedFromInputsAsset::class,
39+
PNotifyAsset::class,
40+
ReminderTopAsset::class,
41+
CheckboxStyleAsset::class,
3442
];
3543
}

src/assets/ApplyToAllAsset.php

+6-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace hipanel\assets;
56

6-
77
use yii\web\AssetBundle;
8+
use yii\web\JqueryAsset;
89

910
class ApplyToAllAsset extends AssetBundle
1011
{
11-
/**
12-
* {@inheridoc}
13-
*/
14-
public $sourcePath = __DIR__;
15-
16-
/**
17-
* {@inheridoc}
18-
*/
19-
public $js = [
20-
'js/ApplyToAll.js'
21-
];
22-
23-
/**
24-
* {@inheridoc}
25-
*/
12+
public $sourcePath = __DIR__ . '/js';
13+
public $js = ['ApplyToAll.js'];
2614
public $depends = [
27-
'yii\web\JqueryAsset',
28-
];
29-
30-
/**
31-
* {@inheridoc}
32-
*/
33-
public $publishOptions = [
34-
'linkAssets' => true,
15+
JqueryAsset::class,
3516
];
17+
public $publishOptions = ['only' => ['ApplyToAll.js']];
3618
}

src/assets/BootstrapAsset.php

-15
This file was deleted.

src/assets/BootstrapDatetimepickerAsset.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@
1010

1111
namespace hipanel\assets;
1212

13+
use yii\bootstrap\BootstrapAsset;
1314
use yii\web\AssetBundle;
1415
use yii\web\JqueryAsset;
1516

1617
class BootstrapDatetimepickerAsset extends AssetBundle
1718
{
1819
public $sourcePath = '@bower/eonasdan-bootstrap-datetimepicker/build';
19-
20-
public $js = [
21-
'js/bootstrap-datetimepicker.min.js',
22-
];
23-
24-
public $css = [
25-
'css/bootstrap-datetimepicker.min.css',
26-
];
27-
20+
public $js = ['js/bootstrap-datetimepicker.min.js'];
21+
public $css = ['css/bootstrap-datetimepicker.min.css'];
2822
public $depends = [
2923
JqueryAsset::class,
3024
BootstrapAsset::class,

src/assets/CheckboxStyleAsset.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212

1313
class CheckboxStyleAsset extends \yii\web\AssetBundle
1414
{
15-
/**
16-
* {@inheritdoc}
17-
*/
1815
public $sourcePath = __DIR__ . '/css';
19-
20-
/**
21-
* {@inheritdoc}
22-
*/
2316
public $css = ['checkbox-style-asset.css'];
17+
public $publishOptions = ['only' => ['checkbox-style-asset.css']];
2418
}

src/assets/CheckboxesAsset.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
class CheckboxesAsset extends AssetBundle
1616
{
17-
public $sourcePath = '@npm/checkboxes.js';
18-
19-
public $js = [
20-
'dist/jquery.checkboxes-1.2.0' . (YII_DEBUG ? '.js' : '.min.js'),
21-
];
17+
public $sourcePath = '@npm/checkboxes.js/dist';
18+
public $js = ['jquery.checkboxes-1.2.0' . (YII_DEBUG ? '.js' : '.min.js')];
2219
}

src/assets/CondensedFromInputsAsset.php

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace hipanel\assets;
55

6+
use yii\bootstrap\BootstrapAsset;
67
use yii\web\AssetBundle;
78

89
class CondensedFromInputsAsset extends AssetBundle

src/assets/DoubleClickPreventAsset.php

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace hipanel\assets;
44

5+
use yii\bootstrap\BootstrapAsset;
56
use yii\web\AssetBundle;
67
use yii\web\JqueryAsset;
78

src/assets/FontAwesome.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
class FontAwesome extends AssetBundle
1616
{
1717
public $sourcePath = '@bower/components-font-awesome';
18-
19-
public $css = [
20-
'css/font-awesome.min.css',
18+
public $css = [(YII_DEBUG ? 'css/font-awesome.css' : 'css/font-awesome.min.css')];
19+
public $publishOptions = [
20+
'only' => ['fonts/*', 'css/*'],
2121
];
2222
}

src/assets/LessSpaceAsset.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
class LessSpaceAsset extends AssetBundle
1616
{
17-
public $sourcePath = '@bower/less-space';
18-
19-
public $css = [
20-
'dist/less-space.min.css',
21-
];
17+
public $sourcePath = '@bower/less-space/dist';
18+
public $css = ['less-space.min.css'];
2219
}

src/assets/Vue2CdnAsset.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace hipanel\assets;
@@ -7,6 +8,6 @@
78

89
class Vue2CdnAsset extends AssetBundle
910
{
10-
public $sourcePath = __DIR__;
11+
public $sourcePath = null;
1112
public $js = [(YII_DEBUG ? 'https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js' : 'https://cdn.jsdelivr.net/npm/vue@2')];
1213
}

0 commit comments

Comments
 (0)