Sha256: 508603d7a6ecd7f6e65ab8841aae21a462c4225c22931d297d174358fbc73aa0

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module SewingKit
  module Webpack
    class Dev
      attr_accessor :pid

      def start
        @pid = spawn
        detach
      end

      private

      def command
        cmd = [
          'node_modules/.bin/sewing-kit',
          'dev',
          '--config-file',
          'config/sewing-kit.config.js',
          '--target',
          'client',
          '--env',
          node_env
        ]

        if hmr?
          cmd += ['--hot', '--hot-host', hot_host]
        else
          cmd += ['--lazy', '--super-speed']
        end

        cmd += ['--verbose'] if ::Rails.configuration.sewing_kit.webpack.verbose

        cmd
      end

      def spawn
        Kernel.spawn(
          { 'NODE_ENV' => node_env },
          *command,
          chdir: Rails.root.to_s,
          out: $stdout,
          err: $stderr,
        ) || exit(1)
      end

      def detach
        Process.detach pid
      end

      def hmr?
        @hmr ||= ENV['SK_DISABLE_HMR'] != 'true'
      end

      def hot_host
        if host = ::Rails.configuration.sewing_kit.webpack.asset_host
          if host.is_a?(Proc) || host.respond_to?(:call)
            host.call(nil, nil)
          else
            host
          end
        else
          "/"
        end
      end

      private
      def node_env
        ENV['NODE_ENV'] || Rails.env.to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sewing_kit-0.4.6 lib/sewing_kit/webpack/dev.rb