-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support React on Rails by merging Webpacker Lite
See #594 From a long discussion on #464, this issue will summarize. I'll soon be posting proposed changes to the README.md. Summary of changes * Move base url out from manifest.json to manifest.rb * Assign env variables to dev server settings so it can be overridden at runtime. * The keys for dev_server should use same format as of now as documented in Paths on the README.md. Note that * hot is a new setting to indicate that the dev_server is used with hot reloading, which means that CSS should be inlined to be hot loaded. The presence of dev_server means that the webpack-dev-server is used for the given env. development: // put the created files to the /public/webpack/development directory public_output_path: webpack/development //# if dev_server is not provided, then dev_server is not used dev_server: hot: true # This is a new setting static: false host: localhost https: false
- Loading branch information
Showing
18 changed files
with
424 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ development: | |
host: localhost | ||
port: 8080 | ||
https: false | ||
hot: false | ||
|
||
test: | ||
<<: *default | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Same convention as manifest/configuration.rb | ||
|
||
# Loads webpacker configuration from config/webpacker.yml | ||
|
||
require "webpacker/configuration" | ||
|
||
class Webpacker::DevServer < Webpacker::FileLoader | ||
class << self | ||
def dev_server? | ||
!dev_server_values.nil? | ||
end | ||
|
||
# read settings for dev_server | ||
def hot? | ||
return false unless dev_server? | ||
if ENV["WEBPACKER_HMR"].present? | ||
val = ENV["WEBPACKER_HMR"].downcase | ||
return true if val == "true" | ||
return false if val == "false" | ||
raise new ArgumentError("WEBPACKER_HMR value is #{ENV['WEBPACKER_HMR']}. Set to TRUE|FALSE") | ||
end | ||
fetch(:hot) | ||
end | ||
|
||
def host | ||
fetch(:host) | ||
end | ||
|
||
def port | ||
fetch(:port) | ||
end | ||
|
||
def https? | ||
fetch(:https) | ||
end | ||
|
||
def protocol | ||
https? ? "https" : "http" | ||
end | ||
|
||
def file_path | ||
Webpacker::Configuration.file_path | ||
end | ||
|
||
# Uses the hot_reloading_host if appropriate | ||
def base_url | ||
"#{protocol}://#{host}:#{port}" | ||
end | ||
|
||
private | ||
|
||
def dev_server_values | ||
data.fetch(:dev_server, nil) | ||
end | ||
|
||
def fetch(key) | ||
return nil unless dev_server? | ||
dev_server_values.fetch(key, dev_server_defaults[key]) | ||
end | ||
|
||
def data | ||
load_instance if Webpacker.env.development? | ||
unless instance | ||
raise Webpacker::FileLoader::FileLoaderError.new("Webpacker::DevServer.load_data must be called first") | ||
end | ||
instance.data | ||
end | ||
|
||
def dev_server_defaults | ||
@defaults ||= Webpacker::Configuration.defaults[:dev_server] | ||
end | ||
end | ||
|
||
private | ||
def load_data | ||
Webpacker::Configuration.instance.data | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.