Class: Condenser::TerserMinifier
- Inherits:
-
NodeProcessor
- Object
- NodeProcessor
- Condenser::TerserMinifier
- Defined in:
- lib/condenser/minifiers/terser_minifier.rb
Instance Attribute Summary
Attributes inherited from NodeProcessor
Instance Method Summary collapse
- #call(environment, input) ⇒ Object
-
#initialize(dir, options = {}) ⇒ TerserMinifier
constructor
A new instance of TerserMinifier.
Methods inherited from NodeProcessor
#binary, call, #exec_runtime, #exec_runtime_error, #exec_syntax_error, #name, #npm_install, #npm_module_path, setup
Constructor Details
#initialize(dir, options = {}) ⇒ TerserMinifier
Returns a new instance of TerserMinifier.
3 4 5 6 7 8 9 10 11 |
# File 'lib/condenser/minifiers/terser_minifier.rb', line 3 def initialize(dir, = {}) super(dir) npm_install('terser') @options = .merge({ keep_classnames: true, keep_fnames: true }).freeze end |
Instance Method Details
#call(environment, input) ⇒ Object
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 |
# File 'lib/condenser/minifiers/terser_minifier.rb', line 13 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 Terser = require("#{npm_module_path('terser')}"); const source = #{JSON.generate(input[:filename] => input[:source])} const options = #{JSON.generate(opts)}; Terser.minify(source, options).then((result) => { console.log(JSON.stringify(result)); }, (error) => { console.log(JSON.stringify({'error': error.name + ": " + error.message})); process.exit(1); }); JS exec_runtime_error(result['error']) if result['error'] result['warnings']&.each { |w| environment.logger.warn(w) } input[:source] = result['code'] input[:map] = result['map'] end |