Webpacker: view helper not adding digest string to file name

Created on 7 Apr 2017  路  7Comments  路  Source: rails/webpacker

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.

style loaders

Most helpful comment

@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.

All 7 comments

@avifoxi Maybe comments there will help? https://github.com/rails/webpacker/issues/24

@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

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

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

@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.

Feel free to close the issue if you are happy 馃槃

thanks - yes, closing!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

towry picture towry  路  3Comments

johan-smits picture johan-smits  路  3Comments

ijdickinson picture ijdickinson  路  3Comments

ankitrg picture ankitrg  路  3Comments

vtno picture vtno  路  3Comments