Class: Condenser::UglifyMinifier
- Inherits:
-
NodeProcessor
- Object
- NodeProcessor
- Condenser::UglifyMinifier
- Defined in:
- lib/condenser/minifiers/uglify_minifier.rb
Overview
From npm install uglify-js
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
- #call(environment, input) ⇒ Object
-
#initialize(options = {}) ⇒ UglifyMinifier
constructor
A new instance of UglifyMinifier.
Methods inherited from NodeProcessor
#binary, #exec_runtime, #exec_runtime_error, #exec_syntax_error, node_modules_path, #node_modules_path, setup
Constructor Details
#initialize(options = {}) ⇒ UglifyMinifier
Returns a new instance of UglifyMinifier.
11 12 13 14 15 |
# File 'lib/condenser/minifiers/uglify_minifier.rb', line 11 def initialize( = {}) @options = .merge({ warnings: true }).freeze end |
Class Method Details
.call(environment, input) ⇒ Object
7 8 9 |
# File 'lib/condenser/minifiers/uglify_minifier.rb', line 7 def self.call(environment, input) new.call(environment, input) end |
Instance Method Details
#call(environment, input) ⇒ Object
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 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/condenser/minifiers/uglify_minifier.rb', line 17 def call(environment, input) opts = { # 'moduleRoot' => nil, # 'filename' => input[:filename], # 'moduleId' => input[:filename].sub(/(\..+)+/, ''), # 'filenameRelative' => input[:filename],#split_subpath(input[:load_path], input[:filename]), # 'sourceFileName' => input[:filename], # 'sourceMapTarget' => input[:filename] # # 'inputSourceMap' }.merge(@options) result = exec_runtime(<<-JS) const UglifyJS = require("#{File.('../node_modules', __FILE__)}/uglify-js"); const source = #{JSON.generate(input[:filename] => input[:source])} const options = #{JSON.generate(opts)}; // { // sourceMap: { // content: "content from compiled.js.map", // url: "minified.js.map" // } // }); try { var result = UglifyJS.minify(source, options); console.log(JSON.stringify(result)); } catch(e) { console.log(JSON.stringify({'error': e.name + ": " + e.message})); process.exit(1); } JS raise Error, result['error'] if result['error'] if result['warnings'] result['warnings'].each { |w| environment.logger.warn(w) } end input[:source] = result['code'] input[:map] = result['map'] end |