Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uglifyjs with sourcemaps option and file list. #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/Filter/Uglifyjs.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ class Uglifyjs extends AssetFilter
'options' => '',
);

/**
* Input filter.
*
* @param string $filename Name of the file
* @param string $content Content of the file.
* @return string
*/
public function input($filename, $content)
{
$this->files[] = $filename;
return $content;
}
/**
* Run `uglifyjs` against the output and compress it.
*
Expand All @@ -41,8 +53,14 @@ class Uglifyjs extends AssetFilter
*/
public function output($filename, $input)
{
$cmd = $this->_settings['node'] . ' ' . $this->_settings['uglify'] . ' - ' . $this->_settings['options'];
$files = implode(' ', $this->files);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this correctly escape files with spaces in their names?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No for relative paths.

$cmd =
$this->_settings['node'] . ' ' .
$this->_settings['uglify'] . ' ' .
$files . ' ' .
$this->_settings['options'];

$env = array('NODE_PATH' => $this->_settings['node_path']);
return $this->_runCmd($cmd, $input, $env);
return $this->_runCmd($cmd, '', $env);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this break filter chains that involve pre-processors and uglify? For example combining the coffescript or sprockets filter and uglify will no longer work as uglify will be told to use the source files and not the transformed results of those files.

}
}