-
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
Follow app/javascript/application.js convention from Rails 7 #3156
Conversation
So it remains compatible with other bundler setups, like esbuild-rails.
We can add them via Rails 7 installers
What's the reasoning behind this change? I feel like |
|
So the "my_component.js" will be processed as the entry point. What if you have files that you don't want to be entry points, at least because of compile performance? You will need to set up something like app/javascript_lib ? |
@crawler Entrypoints are limited to the top level, so app/javascript by default. app/javascript/components (or whatever) is where you'll put anything not a entry point. |
Yeah I don’t think we will find something that works for everyone in all cases. But Webpacker is quite flexible with the setup it has now. Easy to change! |
FYI, when I tried this, I noticed that webpack ended up searching for files recursively under "entry": {
"application": "app/javascript/application.js",
"common/array/chunk": "app/javascript/common/array/chunk.ts",
"common/http_interceptors/add_csrf_token": "app/javascript/common/http_interceptors/add_csrf_token.ts",
"common/invertMap": "app/javascript/common/invertMap.tsx",
"common/utils": "app/javascript/common/utils.ts",
…
}, Unless there's some way to make it only look at the top level of As a workaround, I ended up changing the config back to a "dead-end" (no subdirs for it to recurse) directory: source_entry_path: entrypoints |
Yes there’s a change to the JS glob that goes in the @rails/webpacker module only to look at the top level. Not nested. |
Thanks, that did the trick. ( |
This should add back the ability to namespace packs which was removed in rails#3156 at the cost of needing to specify each of the nested directories in `source_entry_path`. Defining each namespace will make sure directories like `app/javascript/src`, `app/javascript/stylesheets`, etc don't get entries assigned. * Move the entry parsing into `parseEntryPath` in `package/utils/helpers.js` * Change `getEntryObject` to use `parseEntryPath` and to check whether `source_entry_path` is an array * Add a nested pack into the test app
@@ -16,7 +16,7 @@ const getEntryObject = () => { | |||
const entries = {} | |||
const rootPath = join(config.source_path, config.source_entry_path) | |||
|
|||
globSync(`${rootPath}/**/*.*`).forEach((path) => { | |||
globSync(`${rootPath}/*.*`).forEach((path) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source_entry_path
from packs
to /
In that case,
// This behavior retained
app/javascript/packs/application.js
// Missing pack file
app/javascript/packs/foo/fooPack.js
app/javascript/packs/foo/fooPack.scss
To ensure compatibility across the different JavaScript bundler options supported by Rails 7 (like esbuild-rails), we need to use the same entry point by default. That entry point is going to be
app/javascript/application.js
. You can of course continue to change that in yourwebpacker.yml
config, but by sharing the same default, we can make other generators work out of the box.