usabilityhub / rails-erb-loader

Embedded Ruby (.erb) webpack loader for Ruby projects.
MIT License
103 stars 28 forks source link

unclarity/bug when using rails-erb-loader-dependencies directive in non-js files #107

Open bertBruynooghe opened 2 years ago

bertBruynooghe commented 2 years ago

I spent quite some time figuring out I needed the following syntax to get dependencies detected for my .html.erb files:

<!-- /* rails-erb-loader-dependencies ... */ -->

I see two solutions:

  1. document this properly
  2. iso. /* rails-erb-loader-dependencies ... */ implement searching for: rails-erb-loader-dependencies (which allows users to use the proper comment syntax for the resulting file, and which is backwards compatible)

It would also be fine if we could support <%# rails-erb-loader-dependencies ... %>, which leaves no traces in the end result, and would also work for stuff that doesn't support comments (e.g. .json.erb)

I am willing to create a PR for this if you decide which of the two solutions you prefer...

PikachuEXE commented 2 years ago

I think we should simply update doc on https://github.com/usabilityhub/rails-erb-loader#dependencies for this special case. I have never used rails-erb-loader-dependencies in .html.erb so I have no idea that syntax is required. (I don't even know how it works and I have only contributed a few things 😆 )

rhys-vdw commented 2 years ago

If you don't want the directive to end up in the result, or wish to use it outside of a javascript context, include the javascript comment block inside an erb comment block.

The reason this was not included in the docs is because comments should be removed in minification in your release build (same goes for all preprocessor directive comments, eslint etc etc)