Right now, javascript_pack_tag just outputs on the root path of the current host. It should be possible to configure the host and the prefix path just like it is with the asset pipeline. Chief benefit is to allow for use of CDNs.
Not sure if this should be a separate issue. I can't seem to use javascript_pack_tag without fingerprinting.
<%= javascript_pack_tag 'hello_vue-ceb9bfb89eb3dbc910d5' %> #works
<%= javascript_pack_tag 'hello_vue' %> #/packs/hello_vue.js not found
@ytbryan that would be a separate issue
Is there a reason to use content_tag(:script) over javascript_include_tag. We roll our own webpack pipeline currently and use a helper that reads stats.json and uses javascript_include_tag. This gets the correct asset host configuration in production.
Using javascript_include_tag makes things go through the asset pipeline.
That doesn't happen with these Webpacker packs by intent. We don't want
Webpack JavaScripts to live in app/assets/javascripts. This is a completely
separate pipeline.
On Sat, Dec 17, 2016 at 4:05 PM, Drew Hamlett notifications@github.com
wrote:
Is there a reason to use content_tag(:script) over javascript_include_tag.
We roll our own webpack pipeline currently and use a helper that reads
stats.json and uses javascript_include_tag. This gets the correct asset
host configuration in production.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/rails/webpacker/issues/22#issuecomment-267795067, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAKtcb7-94WpTQ6lnFv1_T_kFlDdes1ks5rJHjDgaJpZM4LKzAU
.
What do you think of configuration keys specific to webpacker but if those keys are not defined explicitly by the developer it would use by default the Rails asset pipeline asset_host and asset_path keys?
I don't think we need to be that clever. Perhaps we can call it out in the
config files, though. You can always just assign these things to the same
value.
On Mon, Dec 19, 2016 at 6:33 AM, Nicolas Blanco notifications@github.com
wrote:
What do you think of configuration keys specific to webpacker but if those
keys are not defined explicitly by the developer it would use by default
the Rails asset pipeline asset_host and asset_path keys?—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/rails/webpacker/issues/22#issuecomment-267977935, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAKtU8XwC4ifQf0-R1rfMPShMydSZO0ks5rJpWigaJpZM4LKzAU
.
@dhh I this case is possible to delegate javascript_pack_tag to javascript_include_tag and the asset won't go through asset pipeline because Webpacker::Source#path returns the assets prefixed by /. In this case the full asset path will be computed by Action View and the host set in config.action_controller.asset_host will be used.
With this change:
diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb
index ec68903..5875729 100644
--- a/lib/webpacker/helper.rb
+++ b/lib/webpacker/helper.rb
@@ -15,6 +15,6 @@ module Webpacker::Helper
# <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
# <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
def javascript_pack_tag(name, **options)
- content_tag('script', '', src: Webpacker::Source.new(name).path, **options)
+ javascript_include_tag(Webpacker::Source.new(name).path, **options)
end
end
and setting in a Rails app:
Rails.application.config.action_controller.asset_host = "https://cdn.basecamp.com"
You will get this using javascript_pack_tag:
irb(main):001:0> helper.javascript_pack_tag("application")
=> "<script src=\"https://cdn.basecamp.com/packs/application-2ca6e6fb384adada6b2f.js\"></script>"
Personally 👍 — though we'd need a test demonstrating it starts with a slash or ideally one that shows it skips the pipeline.
Ah, yes. That's good. Forgot about the slash-starting skip. I'd say this is good 👍
currently having issue with javascript_pack_tag 'app' returning /javascripts/packs/app.js instead of just /packs/app.js is it should.
Looks like it's because: Webpacker::Source.new(name).path returns packs/app.json and https://github.com/rails/rails/blob/8d009674af182f369b5e9d2a587dbf625dcdd0c4/actionview/lib/action_view/helpers/asset_url_helper.rb#L194 returning true since there's a slash in the string (at all, not just beginning or end).
uncertain the best fix, but it's breaking my rails 5.0.1 + webpacker build, been stuck for a while on it.
U can try change output.publicPath in production webpack config (config/webpack/production.js) like:
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const environment = require('./environment')
environment.config.set('output.publicPath', '/prefix/')
module.exports = environment.toWebpackConfig()
Most helpful comment
@dhh I this case is possible to delegate
javascript_pack_tagtojavascript_include_tagand the asset won't go through asset pipeline becauseWebpacker::Source#pathreturns the assets prefixed by/. In this case the full asset path will be computed by Action View and the host set inconfig.action_controller.asset_hostwill be used.With this change:
and setting in a Rails app:
You will get this using
javascript_pack_tag: