-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: support multiple source entry regex paths #585
Comments
@jeromedalbert You could mirror same by requiring these files into a webpacker pack like so: // app/javascript/packs/marketing/home.js
import '../../assets/css/marketing.css'
// .... rest of the code // app/javascript/packs/app/home.js
import '../../assets/css/app.css'
// .... rest of the code <% content_for :stylesheets do %>
<%= stylesheet_pack_tag 'marketing/home', media: 'all' %>
<% end %>
<% content_for :stylesheets do %>
<%= stylesheet_pack_tag 'app/home', media: 'all' %>
<% end %>
<% content_for :javascripts do %>
<%= javascript_pack_tag 'marketing/home' %>
<% end %>
<% content_for :javascripts do %>
<%= javascript_pack_tag 'app/home' %>
<% end %> What do you think? |
Right, in my case I have only migrated the JS files to Webpacker, and kept the CSS/images/fonts in the asset pipeline, since I had no particular reason to migrate them so far. But even if I migrated the CSS all the way, your suggestion implies that I have to type my CSS declarations twice. First with As for the JS files, if I am not mistaken, it looks like the convention is to use Now I realize that organizing JS files my way is not mentioned in the Webpacker README at all. I just thought that since the Rails asset pipeline already allowed such organizations (with minimum boilerplate) thanks to Sorry if I was unclear, I can explain further if needed. Also, if I am only one of the rare weirdos with this kind of JS/CSS organization, we can just close this issue and keep it as a reference for a future hypothetical other weirdo. 😄 |
+1 for this. I don't need any of the regex portions of this, but I would like to have multiple entry points. For example, our organization has a style guide where our designer creates components for our main application. We pull this in through a submodule and have other SPA-like components independent from the main style guide, if not just external assets. @jeromedalbert, do you have a branch for this? Would love to check it out and provide you with some feedback / maybe collaborate on making this into a PR. |
@mach-kernel Yeah, here is my branch. It supports the existing Although for your use case, since you don't need regex globs, you could make it work with current Webpacker by just adding one file per entry point in |
@jeromedalbert thanks for the branch! The reason would be mainly to keep the two entry points in different directories. I want to keep my Git submodule at the root of my project to make it easier to access (again, not a hard breaking issue, but "in a perfect world it would be nice if"-kind of thing). 😺 |
@gauravtiwari Should I make a PR or should we close the issue? |
@jeromedalbert Sorry about the delay, didn't fully understand the scope earlier. I am not sure if we should support multiple entrypoint directories by default - for best practice reasons. Probably useful for app that is transitioning but ideally for developer experience it would be nice to have all entries at one place, which is how you would like to have in the longer term. You can also use subfolders for packs to namespace the entries a.k.a packs. app/javascript:
marketing:
src:
components:
- home.js
- calendar.js
calendar:
src:
components:
- chart.js
packs:
marketing:
- home.js
- calendar.js What do you think? BTW made a PR (#557) for having multiple resolved_paths: ['app/assets'] Then import them inside your packs like so: // Note it's relative to parent directory i.e. app/assets
import 'stylesheets/main'
import 'images/rails.png'
Taken from your above comment, no it's not just a reference. The packs are made solely for webpack entry points i.e. a file from where the compilation will start and will also emit a bundle of the same name. The |
To mirror Rails' ability to add additional assets in
config/initializers/assets.rb
, it would be nice if Webpacker could do the same for entry paths.For example in one of my apps, I have the following asset configuration:
The file above used to precompile JS on top of CSS. But now that I have moved all my JavaScript "sprinkle code" over to Webpack (because I want all the app to use next generation JavaScript), I needed a similar feature for Webpacker.
Here's what I have done to make this work:
That's it. I think this could be a common enough use case, especially in apps that bundle one CSS stylesheet and one JS file per page, like the one I am currently working on:
Do you guys think it would be useful to have this feature in Webpacker? I could do a PR with the modifications above.
The text was updated successfully, but these errors were encountered: