1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace nystudio107\transcoder\variables; |
4
|
|
|
|
5
|
|
|
use nystudio107\transcoder\helpers\Manifest as ManifestHelper; |
6
|
|
|
use nystudio107\transcoder\assetbundles\transcoder\TranscoderAsset; |
7
|
|
|
|
8
|
|
|
use Craft; |
9
|
|
|
use craft\helpers\Template; |
10
|
|
|
|
11
|
|
|
class ManifestVariable |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
// Protected Static Properties |
14
|
|
|
// ========================================================================= |
15
|
|
|
|
16
|
|
|
protected static $config = [ |
17
|
|
|
// If `devMode` is on, use webpack-dev-server to all for HMR (hot module reloading) |
18
|
|
|
'useDevServer' => true, |
19
|
|
|
// Manifest names |
20
|
|
|
'manifest' => [ |
21
|
|
|
'legacy' => 'manifest-legacy.json', |
22
|
|
|
'modern' => 'manifest.json', |
23
|
|
|
], |
24
|
|
|
// Public server config |
25
|
|
|
'server' => [ |
26
|
|
|
'manifestPath' => '/', |
27
|
|
|
'publicPath' => '/', |
28
|
|
|
], |
29
|
|
|
// webpack-dev-server config |
30
|
|
|
'devServer' => [ |
31
|
|
|
'manifestPath' => 'http://127.0.0.1:8080', |
32
|
|
|
'publicPath' => '/', |
33
|
|
|
], |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
// Public Methods |
37
|
|
|
// ========================================================================= |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* ManifestVariable constructor. |
41
|
|
|
*/ |
42
|
|
|
public function __construct() |
43
|
|
|
{ |
44
|
|
|
ManifestHelper::invalidateCaches(); |
45
|
|
|
$bundle = new TranscoderAsset(); |
46
|
|
|
self::$config['server']['manifestPath'] = Craft::getAlias($bundle->sourcePath); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
|
|
|
|
50
|
|
|
* @param string $moduleName |
|
|
|
|
51
|
|
|
* @param bool $async |
|
|
|
|
52
|
|
|
* @param null|array $config |
|
|
|
|
53
|
|
|
* |
54
|
|
|
* @return null|\Twig_Markup |
55
|
|
|
* @throws \yii\web\NotFoundHttpException |
56
|
|
|
*/ |
57
|
|
|
public function includeCssModule(string $moduleName, bool $async = false, $config = null) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
return Template::raw( |
60
|
|
|
ManifestHelper::getCssModuleTags(self::$config, $moduleName, $async) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the uglified loadCSS rel=preload Polyfill as per: |
67
|
|
|
* https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public static function includeCssRelPreloadPolyfill(): string |
72
|
|
|
{ |
73
|
|
|
return Template::raw( |
74
|
|
|
ManifestHelper::getCssRelPreloadPolyfill() |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
|
|
|
|
79
|
|
|
* @param string $moduleName |
|
|
|
|
80
|
|
|
* @param bool $async |
|
|
|
|
81
|
|
|
* @param null|array $config |
|
|
|
|
82
|
|
|
* |
83
|
|
|
* @return null|\Twig_Markup |
84
|
|
|
* @throws \yii\web\NotFoundHttpException |
85
|
|
|
*/ |
86
|
|
|
public function includeJsModule(string $moduleName, bool $async = false, $config = null) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
return Template::raw( |
89
|
|
|
ManifestHelper::getJsModuleTags(self::$config, $moduleName, $async) |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Return the URI to a module |
95
|
|
|
* |
96
|
|
|
* @param string $moduleName |
|
|
|
|
97
|
|
|
* @param string $type |
|
|
|
|
98
|
|
|
* @param null $config |
|
|
|
|
99
|
|
|
* |
100
|
|
|
* @return null|\Twig_Markup |
101
|
|
|
* @throws \yii\web\NotFoundHttpException |
102
|
|
|
*/ |
103
|
|
|
public function getModuleUri(string $moduleName, string $type = 'modern', $config = null) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
return Template::raw( |
106
|
|
|
ManifestHelper::getModule(self::$config, $moduleName, $type) |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Include the Safari 10.1 nomodule fix JavaScript |
112
|
|
|
* |
113
|
|
|
* @return \Twig_Markup |
114
|
|
|
*/ |
115
|
|
|
public function includeSafariNomoduleFix() |
116
|
|
|
{ |
117
|
|
|
return Template::raw( |
118
|
|
|
ManifestHelper::getSafariNomoduleFix() |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|