Multiple javascript_pack_tag calls for different packs in one template hierarchy #1348
Unanswered
bubulusWork
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there,
I am facing an issue with the way different packs can be used in one template hierarchy. It looks like it's not okay to include two different packs within the same template (or make another call in a lower level of the template hierarchy).
Let's say I have this directory tree inside app/javascript, assuming packs is the default, so: app/javascript/packs
lets say, I define two packs:
Now In a template file (in my case .slim), I assumed, that shipping two packs like this, was possible:
But this wont work, because for two reasons:
A) rails is complaining:
To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide
And B) the Namespace is wrong:
And this is essentially where my problem is, the way the namespaces are constructed, is not making it possible for me to use more than one pack, which in turn would enable me to be very granular in bundle splits. That's at least my understanding...
I did refer to the docs (I probably read these several times at this point), and from what I understood, I can just make one call with two packs as args (at least that's what I saw in a place in my codebase):
But this will not work, because the last pack in the call will set the namespace (barDir) so FooComponent cannot be found. Which will also lead to an error...
In short, I need a way to make these kinds of splits, but I cannot afford to remove packs, like for example only to use fooDir. I have to work with the fact, that upwards in the template hierarchy is lots of legacy code both from sprockets and react code, that just won't go away any time soon.
I know that in theory, I could just move all of the code into either fooDir or barDir, and call it a day. But a much much more preferred choice would be to have two namespaces, so this is possible:
Or at least some hackery way of achieving this... Is this possible?
Beta Was this translation helpful? Give feedback.
All reactions