1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2015 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
namespace Magento \Framework \Css \PreProcessor \Adapter \Less ;
7
7
8
+ use Magento \Framework \App \Filesystem \DirectoryList ;
9
+ use Magento \Framework \App \ObjectManager ;
8
10
use Magento \Framework \App \State ;
9
11
use Magento \Framework \Css \PreProcessor \File \Temporary ;
10
12
use Magento \Framework \Phrase ;
16
18
17
19
/**
18
20
* Class Processor
21
+ *
22
+ * Process LESS files into CSS
19
23
*/
20
24
class Processor implements ContentProcessorInterface
21
25
{
@@ -39,24 +43,32 @@ class Processor implements ContentProcessorInterface
39
43
*/
40
44
private $ temporaryFile ;
41
45
46
+ /**
47
+ * @var DirectoryList
48
+ */
49
+ private DirectoryList $ directoryList ;
50
+
42
51
/**
43
52
* Constructor
44
53
*
45
54
* @param LoggerInterface $logger
46
55
* @param State $appState
47
56
* @param Source $assetSource
48
57
* @param Temporary $temporaryFile
58
+ * @param ?DirectoryList $directoryList
49
59
*/
50
60
public function __construct (
51
61
LoggerInterface $ logger ,
52
62
State $ appState ,
53
63
Source $ assetSource ,
54
- Temporary $ temporaryFile
64
+ Temporary $ temporaryFile ,
65
+ ?DirectoryList $ directoryList = null ,
55
66
) {
56
67
$ this ->logger = $ logger ;
57
68
$ this ->appState = $ appState ;
58
69
$ this ->assetSource = $ assetSource ;
59
70
$ this ->temporaryFile = $ temporaryFile ;
71
+ $ this ->directoryList = $ directoryList ?: ObjectManager::getInstance ()->get (DirectoryList::class);
60
72
}
61
73
62
74
/**
@@ -66,10 +78,19 @@ public function processContent(File $asset)
66
78
{
67
79
$ path = $ asset ->getPath ();
68
80
try {
81
+ $ mode = $ this ->appState ->getMode ();
82
+ $ sourceMapBasePath = sprintf (
83
+ '%s/pub/ ' ,
84
+ $ this ->directoryList ->getPath (DirectoryList::TEMPLATE_MINIFICATION_DIR ),
85
+ );
86
+
69
87
$ parser = new \Less_Parser (
70
88
[
71
89
'relativeUrls ' => false ,
72
- 'compress ' => $ this ->appState ->getMode () !== State::MODE_DEVELOPER
90
+ 'compress ' => $ mode !== State::MODE_DEVELOPER ,
91
+ 'sourceMap ' => $ mode === State::MODE_DEVELOPER ,
92
+ 'sourceMapRootpath ' => '/ ' ,
93
+ 'sourceMapBasepath ' => $ sourceMapBasePath ,
73
94
]
74
95
);
75
96
0 commit comments