Skip to content
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

view helper not adding digest string to file name #244

Closed
avifoxi opened this issue Apr 7, 2017 · 7 comments
Closed

view helper not adding digest string to file name #244

avifoxi opened this issue Apr 7, 2017 · 7 comments

Comments

@avifoxi
Copy link

avifoxi commented Apr 7, 2017

My /public/packs/digests.json looks like this:

{"hello_react":"hello_react-28768036e02c40f28e29.js","application":"application-2a75c5d6537cc8c2e98c.js"}

My template looks like this:

= javascript_pack_tag 'application'
= javascript_pack_tag 'hello_react'

But somehow my embedded script tag in production looks like this:

<script src="//myapp.net/packs/application.js"></script> <!-- where is the digest?! -->
<script src="//myapp.net/packs/hello_react.js"></script>

This is surprising!
Why isn't the view helper appending the digest string?

In my staging environment, I am manually grabbing the digest and this is getting me off the ground. But this kind of defeats the point of having a helper:

- digest = JSON.parse(File.read( Rails.root.join('public', 'packs', 'digests.json')))
  %script{ src: '/packs/' + digest['application'] }
  %script{ src: '/packs/' + digest['hello_react'] }

What may be unusual about my environment:

I cannot perform the webpacker:compile task on my server for many reasons (not relevant for this issue, but performing the compile step on the server is off the table). What this means, for our initial webpack integration, is we are tracking public/packs in git. webpacker:compile is performed on a local machine, where it can fail safely. And all webpack js is precompiled before a deploy. Eventually webpack will do a build in an automated step, also off the main app server.

And I have explicitly cleared the webpacker:compile task in production:

Rake::Task['webpacker:compile'].clear unless Rails.env.development?

So I know that the webpack js + digests files exist, because they're tracked in git.
But I'm not so clear why the helper function is not appending the appropriate digest.

@seppsepp
Copy link

@avifoxi Maybe comments there will help? #24

@gauravtiwari
Copy link
Member

@avifoxi A couple of questions first,

  1. What version of webpacker you on - latest master?
  2. Did you run bundle exec rails webpacker:install after update?
  3. If yes, how did you run webpacker:compile task locally? You see - bundle exec rails webpacker:compile respects current environment so, you need to make sure you set appropriate NODE_ENV or RAILS_VERSION version before running the compile task.

If you run - NODE_ENV=production bundle exec rails webpacker:compile, it should generate assets with proper fingerprints. Let us know

@avifoxi
Copy link
Author

avifoxi commented Apr 10, 2017

Thanks @gauravtiwari for your response!

Good news - this is now working for me.
But is there a discrepancy between webpacker version assumed in the Readme vs what is installed with gem 'webpacker', github: 'rails/webpacker' ?

The configuration change that worked for me is adding:

  config.x.webpacker[:digesting] = true

To my config/environments/production.rb and staging.rb
That is not anywhere in the Readme - which is why I ask.

version

Rails 4.2.7.1, and I am running webpack alongside the asset pipeline, which I cannot deprecate.
Per installation instructions on the Readme, my Gemfile lists:

gem 'webpacker', github: 'rails/webpacker'

And Gemfile.lock says I'm running webpacker v1.0.

did i run the install

yes

how did I run the compile task ?

exactly as you wrote.

So - I am ok to close this, as it does seem to function.
But should anything be added to the readme you think ?
Let me know what you think @gauravtiwari

@avifoxi
Copy link
Author

avifoxi commented Apr 10, 2017

and @seppsepp thanks for the link - the configuration line was in the comment to the issue you linked

@gauravtiwari
Copy link
Member

@avifoxi Great 👍 Yes that correct behaviour because you are using webpacker 1.1 or below. The above configuration won't be needed if you update bundle update webpacker and re-run bundle exec rails webpacker:install plus any corresponding integration installers like react, angular or vue.

Please note that, 1.1 has a lot of breaking changes, especially webpack config files. Please check #153 for more info.

@gauravtiwari
Copy link
Member

Feel free to close the issue if you are happy 😄

@avifoxi
Copy link
Author

avifoxi commented Apr 10, 2017

thanks - yes, closing!

@avifoxi avifoxi closed this as completed Apr 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants