Class: Hippo::Webpack
- Inherits:
-
Object
- Object
- Hippo::Webpack
- Defined in:
- lib/hippo/webpack.rb,
lib/hippo/webpack/client_config.rb
Defined Under Namespace
Classes: ClientConfig
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
Class Method Summary collapse
Instance Method Summary collapse
- #busy? ⇒ Boolean
- #file(entry, raise_on_not_found: true) ⇒ Object
- #host ⇒ Object
-
#initialize ⇒ Webpack
constructor
A new instance of Webpack.
- #start ⇒ Object
- #wait_until_available ⇒ Object
- #webpack_cmd_line_flags ⇒ Object
Constructor Details
#initialize ⇒ Webpack
Returns a new instance of Webpack.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hippo/webpack.rb', line 12 def initialize @assets = {} root = Hippo::Extensions.controlling.root_path @config = ClientConfig.new @config.invoke_all @driver = WebpackDriver::Configuration.new( directory: root, logger: Hippo.logger, file: root.join('config', 'webpack.config.js'), cmd_line_flags: webpack_cmd_line_flags, environment: { NODE_ENV: Hippo.env.production? ? 'production' : 'development' } ) @process = @driver.launch(development: !Hippo.env.production?) end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
6 7 8 |
# File 'lib/hippo/webpack.rb', line 6 def assets @assets end |
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
6 7 8 |
# File 'lib/hippo/webpack.rb', line 6 def driver @driver end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
6 7 8 |
# File 'lib/hippo/webpack.rb', line 6 def process @process end |
Class Method Details
.using_ssl? ⇒ Boolean
8 9 10 |
# File 'lib/hippo/webpack.rb', line 8 def self.using_ssl? ENV['SSL_CERT_PATH'] && ENV['SSL_KEY_PATH'] end |
Instance Method Details
#busy? ⇒ Boolean
55 56 57 |
# File 'lib/hippo/webpack.rb', line 55 def busy? driver.process.in_progress? end |
#file(entry, raise_on_not_found: true) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hippo/webpack.rb', line 59 def file(entry, raise_on_not_found: true) if Webpack.stub "#{entry}.js" else asset = @driver.process.assets[entry] if asset asset.file elsif !raise_on_not_found raise ArgumentError, "asset '#{entry}' was not found" end end end |
#host ⇒ Object
72 73 74 75 |
# File 'lib/hippo/webpack.rb', line 72 def host Hippo.env.production? ? "" : "//#{@driver.process.host}:#{@driver.process.port}" end |
#start ⇒ Object
45 46 47 |
# File 'lib/hippo/webpack.rb', line 45 def start process.start if Hippo.env.development? && !Hippo::Webpack.stub end |
#wait_until_available ⇒ Object
49 50 51 52 53 |
# File 'lib/hippo/webpack.rb', line 49 def wait_until_available return if Hippo.env.production? Hippo.logger.warn("waiting while compilation in progress") if busy? sleep 0.5 while busy? end |
#webpack_cmd_line_flags ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hippo/webpack.rb', line 28 def webpack_cmd_line_flags return [] if Hippo.env.production? flags = [ '--hot', '--inline', '--host', (ENV['HOST'] || 'localhost'), '--port', '8889', ] if Webpack.using_ssl? flags += [ '--https', '--cert', ENV['SSL_CERT_PATH'], '--key', ENV['SSL_KEY_PATH'] ] end flags end |