Sha256: af511b3b77d2c0c4fe04b8c8a0fe2542af3cb1c7c8300fc220e0f181844231b9

Contents?: true

Size: 1.41 KB

Versions: 8

Compression:

Stored size: 1.41 KB

Contents

require 'sprockets'
require 'sprockets/webpack_index'
require 'webpack_rails/require_directive_processor'
require 'webpack_rails/processor'

module WebpackRails
  class SprocketsEnvironment
    DEFAULT_WEBPACK_TASK_CONFIG = {
      dev_server: false,
      protocol: 'http',
      host: 'localhost',
      port: 9876,
    }

    module EnvironmentWebpackInstanceMethods
      def webpack_task_config=(new_webpack_task_config)
        @webpack_task_config = new_webpack_task_config
      end

      def webpack_task_config
        @webpack_task_config.merge(DEFAULT_WEBPACK_TASK_CONFIG).merge(@webpack_task_config)
      end

      def install_webpack_task_processors!
        file_processor = WebpackRails::Processor.configure(webpack_task_config)
        require_directive_processor = WebpackRails::RequireDirectiveProcessor.configure(webpack_task_config)

        register_preprocessor 'application/javascript', file_processor
        register_preprocessor 'text/css', file_processor
        register_preprocessor 'application/javascript', require_directive_processor
        register_preprocessor 'text/css', require_directive_processor
      end

      def index
        Sprockets::WebpackIndex.new(self)
      end
    end

    def self.enhance!(env, webpack_task_config)
      env.extend(EnvironmentWebpackInstanceMethods)
      env.webpack_task_config = webpack_task_config
      env.install_webpack_task_processors!
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
webpack_rails-1.3.1 lib/webpack_rails/sprockets_environment.rb
webpack_rails-1.3.0 lib/webpack_rails/sprockets_environment.rb
webpack_rails-1.2.2 lib/webpack_rails/sprockets_environment.rb
webpack_rails-1.2.1 lib/webpack_rails/sprockets_environment.rb
webpack_rails-1.1.1 lib/webpack_rails/sprockets_environment.rb
webpack_rails-1.1.0 lib/webpack_rails/sprockets_environment.rb
webpack_rails-1.0.1 lib/webpack_rails/sprockets_environment.rb
webpack_rails-1.0.0 lib/webpack_rails/sprockets_environment.rb