rails / webpacker

Use Webpack to manage app-like JavaScript modules in Rails
MIT License
5.31k stars 1.47k forks source link

Webpacker 6 documentation discrepancy #3206

Closed SamShekhovtsov closed 2 years ago

SamShekhovtsov commented 2 years ago

Hi community.

The documentation says: Usage Once installed, you can start writing modern ES6-flavored JavaScript apps right away:

app/javascript:
  # Only Webpack entry files here
  └── application.js
  └── application.css
  └── src:
  │   └── my_component.js
  └── stylesheets:
  │   └── my_styles.css
  └── images:
      └── logo.svg

however when I do rails webpacker:install , it automatically creates application.js file in the app/packs/entrypoints directory. Why it's not as the documentation states? Actual structure is following:

app/packs/entrypoints
     └── application.js
kimyu92 commented 2 years ago

@guillaumebriday Do you know this is expected behavior?

I have also noticed if a pack file is under a subdirectory, it is no longer generating the pack file.

app/packs/ApplicationPack.js - generated app/packs/foo/FooPack.js - skipped (behavior change in v5)

Is that a regression?

justin808 commented 2 years ago

@kimyu92, that's the intended behavior. The packs list maps to webpack entry points. You should flatten out your packs to the top-level directory. The new behavior eliminates the problem of subdirectories creating tons of new, unnecessary entry points.

Here is the code change:

https://github.com/rails/webpacker/commit/5de0fbc1e16d3db0c93202fb39f5b4d80582c682#diff-7af8667a3e36201db57c02b68dd8651883d7bfc00dc9653661be11cd31feeccdL19

I just updated the docs: See https://github.com/rails/webpacker/pull/3227.

guillaumebriday commented 2 years ago

Thanks @justin808