Sha256: e6c65205f4b90527d686fa05f5a2497ee45c153537caa652ea78664c5a0e4c73

Contents?: true

Size: 838 Bytes

Versions: 1

Compression:

Stored size: 838 Bytes

Contents

require 'tilt'
require 'sprockets'
require 'tempfile'
require 'babel/transpiler'

module ES6Tilt
  class ES6Transformer< Tilt::Template
    self.default_mime_type = 'application/javascript'

    def prepare
    end

    def evaluate(scope, locals, &block)

      location = File.dirname(file)
      compacted = Tempfile.new('compacted', location)

      command = `#{Rails.root.join('node_modules','.bin')}/rollup -f iife --no-indent -c #{Rails.root}/rollup.config.js -n #{File.basename(file, ".*").camelize} -- #{file} > #{compacted.path}`

      output = compacted.read
      Rails.logger.info "Bundling es6"
      Rails.logger.info output

      compacted.close
      compacted.unlink
      output
    end

  end
end
Sprockets.register_engine('.es6', ES6Tilt::ES6Transformer)
Sprockets.register_engine('.jsx', ES6Tilt::ES6Transformer)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
es6_tilt-0.1.2 lib/es6_tilt.rb