-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Consolidate configuration into one file and setup caching for manifest #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/webpacker/file_loader.rb
Outdated
def load(path = file_path) | ||
self.instance = new(path) | ||
end | ||
|
||
def reloadable? | ||
["development", "test"].include?(Rails.env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is more common use !Rails.env.production?
in Rails code base but we can check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yepp thought about that too but I only wanted to limit this feature explicitly for - test and development. For ex - folks also might have staging and other environments where they don't want to reload. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think environment is the wrong thing to check here exactly because of that. People may want to enable that in staging, or in an other environment. I'd introduce a new configuration like reload_webpacker
with default to false
and have this config set to true in the development and test environment files. Just like sprockets does with debug option for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Will fix 👍
@guilleiguaran @rafaelfranca Please take a look 👍 |
lib/webpacker/railtie.rb
Outdated
@@ -12,6 +13,10 @@ class Webpacker::Engine < ::Rails::Engine | |||
include Webpacker::Helper | |||
end | |||
|
|||
ActiveSupport.on_load :before_eager_load do | |||
app.config.x.webpacker[:reload] = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of using the x namespace what about creating a webpacker namespace? Also you don't need to use ActiveSupport.on_load :before_eager_load do
. The railtie can set the value in its body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yepp lets do that, now is the good time apparently 😄 Gotcha 👍
lib/webpacker/file_loader.rb
Outdated
def load(path = file_path) | ||
self.instance = new(path) | ||
end | ||
|
||
def reloadable? | ||
Rails.configuration.x.webpacker[:reload] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of coupling webpacker with the Rails, we should be pushing the configuration to Webpacker::FileLoader
from inside the Railtie.
initializer :webpacker do |app|
Webpacker::FileLoade.reloadable = app.config.webpacker.reload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍 Will fix :)
lib/webpacker/file_loader.rb
Outdated
@@ -7,9 +7,17 @@ class FileLoaderError < StandardError; end | |||
attr_accessor :data | |||
|
|||
class << self | |||
def exist? | |||
instance.data.present? rescue false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instance or the data not being there isn't really exceptional or unexpected, so let's use try or & to invocate rather than exception handling.
lib/webpacker/file_loader.rb
Outdated
attr_accessor :data | ||
|
||
class << self | ||
reloadable = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not this be self.reloadable = false
? Otherwise it will only define a local variable.
lib/webpacker.rb
Outdated
@@ -1,4 +1,7 @@ | |||
module Webpacker | |||
mattr_accessor :reload_webpacker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this one? I doesn't seems used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still work in progress, I guess pushed it by mistake 😄
I'd go with |
Yepp makes sense. Will fix 👍 |
Should be good to go now. Updated the PR description to reflect the changes done here 😄 |
CHANGELOG.md
Outdated
Webpacker::Configuration.exist? # => true | ||
``` | ||
|
||
- Add `reloadable?` helper method to check if configuration or manifest is reloaded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nowhere at the moment, just added it as a reverse alias to Webpacker.caching
in case someone wants to use this instead. Probably more readable?
Let's nix code we don't use and program for today. Also need to generally
explain the benefit of not caching.
…On Mon, May 1, 2017 at 9:53 AM, Gaurav Tiwari ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In CHANGELOG.md
<#292 (comment)>:
> +```rb
+# config/environments/production.rb
+config.webpacker.caching = true
+
+# config/environments/staging.rb
+config.webpacker.caching = false
+```
+
+- Add `exist?` helper method to check if configuration or manifest data exist.
+
+```rb
+Webpacker::Manifest.exist? # => false
+Webpacker::Configuration.exist? # => true
+```
+
+- Add `reloadable?` helper method to check if configuration or manifest is reloaded.
Nowhere at the moment, just added it as an alias to Webpacker.caching in
case someone wants to use this instead. Probably more readable?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#292 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAKtRPTUZxnC16gb0ecrlOIEpNZNLA9ks5r1g37gaJpZM4NJSgm>
.
|
Remove redundant assign Fix comment Fix sentence
@dhh This one is ready too 👍 |
This change is more similar to |
@javan We are caching both configuration and manifest here so, not sure if the name should include particular class (instead be more generic) |
I would expect |
Don't want to overload cache_classes. That's specifically for the Ruby auto loader etc.
… On May 10, 2017, at 20:59, Javan Makhmali ***@***.***> wrote:
I would expect config.webpacker.caching to cache compiled assets or something. I wonder if we should just use config.cache_classes from Rails to determine this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I'd prefer something more descriptive then. Maybe |
And, generally, it's confusing that we'll have one environment-specific config option in |
WDYT about combining |
your code is most likely to change on each run, manifest is reloaded | ||
to ensure that latest change and packs has been picked up. | ||
If you want to toggle this behavior in certain | ||
environments you can do it in your `config/webpack/configuration.yml` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think "cache" is the best word to describe this behavior. Perhaps invert it with some form or "reload"? Also, should we apply this behavior more broadly to all file loaders and name it as such? Seems like we'd want configuration.yml
to reload in dev mode too.
Since we're down to a single |
👍
… On May 18, 2017, at 03:06, Javan Makhmali ***@***.***> wrote:
Since we're down to a single .yml file now, what do you think about moving it to config/webpack.yml or config/webpacker.yml? That way config/webpack/ will just be .js files, which feels nice.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Reload Webpacker manifest when
cache_manifest
is set