-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssetBundle.php
150 lines (140 loc) · 4.12 KB
/
AssetBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace mito\assets;
/**
* Modified version of Yii's AssetBundle with support for
* separate development and production assets
*/
class AssetBundle extends \yii\web\AssetBundle
{
/**
* @var array list of development js files
* If this is not null, it will overwrite $js
* If an element is an array, the javascript files in that array
* will be compiled to the javascript file specified in the element's key
*
* For example:
*
* ```php
* public $devJs = [
* 'js/combined.js' => [ 'js/file1.js', 'js/file2.js' ],
* ];
* ```
*
*/
public $devJs = null;
/**
* @var array|null list of development css files
* If this is not null, it will overwrite $css
*/
public $devCss = null;
/**
* @var string the base directory for development assets
*
* You can use either a directory or an alias of the directory.
*/
public $devPath = null;
/**
* @var string the base directory for production assets
*
* You can use either a directory or an alias of the directory.
*/
public $distPath = null;
/**
* @var string relative path to images
*
* Images in this directory will be optimized and copied to the production path
* by the build process
*/
public $imgPath = null;
/**
* @var string relative path to fonts
*
* Files in this directory will be copied to the production path
* by the build process
*/
public $fontPath = null;
/**
* @var array list of paths (relative to base directory) to copy from development directory to production directory on build
*/
public $otherPaths = [];
/**
* @var string relative path to scss files
*
* files in this directory will be compiled to css files in the css directory
* @deprecated use $cssSourcePaths instead
*/
public $scssPath = null;
/**
* @var array relative paths to css source files (scss, less etc.)
*
* files in these directory will be compiled to css files in the css directory
*/
public $cssSourcePaths = [];
/**
* @var array|null extra parameters to pass to gulp.
*/
public $extraParams;
/**
* @var string|boolean|null
* If this is true, it will be overridden by devPath or distPath.
* If it is null, it won't, so that a dummy bundle can still be created from this bundle.
*/
public $sourcePath = true;
private $_distJs = [];
private $_distCss = [];
/**
* {@inheritdoc}
*/
public function init()
{
if ($this->sourcePath === true) {
if (YII_DEBUG) {
$this->_distJs = $this->js;
if ($this->devJs !== null) {
$this->js = [];
foreach ($this->devJs as $name => $scripts) {
if (is_array($scripts)) {
$this->js = array_merge($this->js, $scripts);
} else {
$this->js[] = $scripts;
}
}
}
$this->_distCss = $this->css;
if ($this->devCss !== null) {
$this->css = $this->devCss;
}
if ($this->devPath !== null) {
$this->sourcePath = $this->devPath;
}
} else {
if ($this->distPath !== null) {
$this->sourcePath = $this->distPath;
}
}
}
parent::init();
}
/**
* Returns production js files, even if the environment is in debug mode (YII_DEBUG is true)
* @return array js files
*/
public function getDistJs()
{
if (YII_DEBUG) {
return $this->_distJs;
}
return $this->js;
}
/**
* Returns production css files, even if the environment is in debug mode (YII_DEBUG is true)
* @return array css files
*/
public function getDistCss()
{
if (YII_DEBUG) {
return $this->_distCss;
}
return $this->css;
}
}