How to add subdirectory in javacript_pack_tag from layout in rails 6 and Webpack?

Viewed 1003

In rails 6 , I have <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload'%> in my layout. Since I have some other js files from subfolders that I want add separately so I can split my js files, I tried <%= javascript_pack_tag 'src/javascripts/other', 'data-turbolinks-track': 'reload'%> which is within packs folder. But the browser keep showing

Webpacker can't find src/javascripts/other in ...

I tried a few other variation like /,~other etc., but without success. Can anyone pls explain to what I am missing or the possible causes? Is there a better way to organise files and split codes that can include any amount of files in layout manifest? Thanks I am using rails 6, webpack 4.

1 Answers

According to documentation, if you have the following file:

app/javascript/packs/admin/orders.js

You can use :

<%= javascript_pack_tag 'admin/orders' %>

In your case, you should have:

app/javascript/packs/src/javascripts/other.js

Then you would be able to include it like this :

<%= javascript_pack_tag 'src/javascripts/other' %>
Related