-
Notifications
You must be signed in to change notification settings - Fork 1
/
drupack.theme
45 lines (37 loc) · 1.36 KB
/
drupack.theme
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
<?php
/**
* Implements @see hook_library_info_alter().
*
* This is where — magic — happens.
*/
function drupack_library_info_alter(array &$libraries, string $extension): void
{
$themes = \Drupal::service('extension.list.theme');
if (!$themes->exists($extension)) {
return;
}
$themePath = $themes->getPath($extension);
$resourcesDir = 'public/resources';
$manifestPath = $themePath . '/' . $resourcesDir . '/asset-manifest.json';
if (!file_exists($manifestPath)) {
return;
}
$manifestFile = file_get_contents($manifestPath);
$manifest = json_decode($manifestFile, true);
foreach ($manifest['entrypoints'] as $entrypoints => $entrypoint) {
foreach ($entrypoint as $entry => $files) {
$libraries[$entry]['version'] = 'VERSION';
foreach ($files as $file) {
$pathinfo = pathinfo($file);
switch ($pathinfo['extension']) {
case 'css':
$libraries[$entry]['css']['theme'][$resourcesDir . '/' . $file] = ['preprocess' => false, 'minified' => true];
break;
case 'js':
$libraries[$entry]['js'][$resourcesDir . '/' . $file] = ['preprocess' => false, 'minified' => true];
break;
}
}
}
}
}