Skip to content

Commit

Permalink
Add source maps to all dispatchable resources
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Apr 12, 2019
1 parent 47bb0fe commit 410175d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
11 changes: 11 additions & 0 deletions src/Resources/AbstractDispatchableResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ protected function _processContent()
{
$this->_minify();
}

if($this->getOption('sourcemap', false))
{
$map = $this->_filePath . '.map';
if(file_exists($map))
{
$this->_content .= '/*# sourceMappingURL=data:application/json;charset=utf8;base64,'
. base64_encode(file_get_contents($map))
. '*/';
}
}
}

protected function _minify() { }
Expand Down
20 changes: 2 additions & 18 deletions src/Resources/CssResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
class CssResource extends AbstractDispatchableResource
{
protected $_options = [
'minify' => true,
'dispatch' => true,
'sourcemap' => false,
'minify' => true,
'dispatch' => true,
];

public function getExtension()
Expand Down Expand Up @@ -66,19 +65,4 @@ protected function _minify()
$this->_content = trim($this->_content);
}

protected function _processContent()
{
parent::_processContent();
if($this->getOption('sourcemap', false))
{
$map = $this->_filePath . '.map';
if(file_exists($map))
{
$this->_content .= '/*# //@ sourceMappingURL=data:application/json;charset=utf-8;base64,'
. base64_encode(file_get_contents($map))
. ' /*';
}
}
}

}

0 comments on commit 410175d

Please sign in to comment.