Skip to content

Multiple javascript_pack_tag calls for different packs in one template hierarchy #1348

Closed Answered by bubuluxWork
bubuluxWork asked this question in Q&A
Discussion options

You must be logged in to vote

For those of you who are suffering the same problem, I have a solution (more or less):

You can't declare different namespaces. But you can use a re-export trick to at least keep your file structure like I described.

Say you have two directories: foo and bar. What you could do is re-export your given components under a common pack-namespace, let's call it root. You can, of course, name it however you like.

Now you only defined the pack for the common pack, like this for example:

// packs/root.js
const ReactRailsUJS = require("react_ujs");

const context = require.context("root", true);

ReactRailsUJS.useContext(context);

You can now call components from the root pack with its namespace, sa…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Judahmeek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants