Sha256: ee552b75d6165485d96fea24957f3d563100fb03787b60ffe57fc16d5960fbad

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module VueCli
  module Rails
    require 'vue_cli/rails/helper'

    class Engine < ::Rails::Engine
      initializer 'vue_cli' do |app|
        if ::Rails.env.development? && defined?(::Rails::Server)
          require 'vue_cli/rails/dev_server_proxy'
          app.middleware.insert_before(0, DevServerProxy)
          Engine.start_wds! if ENV['NO_WEBPACK_DEV_SERVER'].blank?
        end

        ::ActiveSupport.on_load(:action_controller) do
          ::ActionController::Base.helper(Helper)
        end

        ::ActiveSupport.on_load(:action_view) do
          include Helper
        end
      end

      def self.start_wds!
        fork do
          config = Configuration.instance
          port = config['devServer']&.dig('port')
          if port
            running = %x`lsof -i:#{port} -sTCP:LISTEN -Pn`&.chop.presence&.split("\n")
            pid = running&.dig(1)&.split(/\s+/, 3)&.dig(1)
            Process.kill('INT', pid.to_i) if pid.present?
          end
          config.node_env.exec(config['launch_dev_service'] || 'vue-cli-service serve')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vue_cli-rails-0.2.0 lib/vue_cli/rails/engine.rb