-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add option to use rails root for node #84
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
Conversation
This PR adds a new rake task, `webpacker:install:root`, which uses `Rails.root` as the root directory for yarn, installing `node_modules, `package.json`, and `yarn.lock` there. `webpacker:install` continues to function as it always has, installing to `vendor`. This only touches the install template - none of the runtime or asset compilation code is affected.
I want to chime in to agree on the subject of I spent the day yesterday configuring Jest testing for a vanilla Rails and Webpacker setup, after seeing a week old, unanswered question on Stack Overflow inquiring how to get JavaScript testing (of any description) working alongside Webpacker. I figured it couldn't be that hard. I was completely wrong. I wrestled with documentation in both the Jest and Babel projects that was self-contradictory and outdated. We can self-righteously condemn the maintainers of these projects for inadequate documentation, but the simple fact of the matter is that only a very tiny minority of their users ever use their product in a project that doesn't follow the convention of placing If this is the situation with two extremely well maintained and highly regarded projects, it's easy to see why a lot of smaller Node projects simply omit support for non-standard configurations like the one implemented by Webpacker. We'll be left in a situation where we're forking JavaScript libraries to support the peculiar Rails way of handling JavaScript dependencies, and at that point we're right back at JavaScript gems. |
Going back to root for everything. Please do update this PR just assume the root 👍 |
Will do! Thanks! |
@guilleiguaran @dhh closing this, updated pr is #101 |
Closes rails#102 As a result of rails#84 and of rails/rails#28093, generating a new rails app with webpacker was raising a conflict in the creation of the `bin/yarn` file. This commit removes that conflict.
Closes rails#102 As a result of rails#84 and of rails/rails#28093, generating a new rails app with webpacker was raising a conflict in the creation of the `bin/yarn` file. This commit removes that conflict.
Closes #102 As a result of #84 and of rails/rails#28093, generating a new rails app with webpacker was raising a conflict in the creation of the `bin/yarn` file. This commit removes that conflict.
I was reading through rails/rails#27245, and thought the best and most "Railsey" solution would be to use
vendor
by default but make other options easy as well.This PR adds a new rake task,
webpacker:install:root
, which usesRails.root
as the root directory for yarn, installingnode_modules
,package.json
andyarn.lock
there.webpacker:install
continues to function as it always has, installing tovendor
.This change is backwards compatible. It just adds some conditionals to the install template; none of the runtime or asset compilation code is affected. All of that as well as all of the instructions in the README still just work, whether you install to vendor or to root.
I think this is a good solution in that it leaves
vendor
as the default but puts the choice in the hands of early adopters, allowing you guys to gather feedback on both approaches.Why it's important to have this choice
I know this has already been discussed, but I want to reiterate why it's important to have this as an option. The Javascript ecosystem has matured, and having
package.json
andnode_modules
in the project root (or at least above all JS code) is one of its few universals. Because of this:vendor
breaks most existing tooling. It can be worked around in some cases, but not in others. E.g. I don't think there's any way at the moment to get Atom'seslint
package to handle this without major nastiness. Bundling one-off solutions for every popular use case (eg third party tools blowing up trying to find package.json and node_modules #41) is not a great solution.vendor
breakspackage.json
scripting, JS land'sbundle exec
/rake
/ binstubs. Instead JS commands have to be wrapped in bin scripts or rake tasks that call out to Javascript. This is gross to implement and especially painful on JRuby. Wouldn't it be nice just to runyarn start
to boot up the frontend?vendor
marginalizes the frontend.vendor
raises the barrier to getting Javascript developers excited about Rails. Their tooling doesn't work, their conventions don't apply, they need to edit obscure Ruby files to do basic things they could otherwise do straightforwardly in JS. Rails has gotten a reputation as being behind the curve on modern frontend development. This won't help.Other notes / topics for bikeshedding
webpacker:install:root
the cleanest way to do this? Should it be a flag or something instead?.tt
files. Currently just using an ENV var.webpacker:install:angular
won’t quite work out of the box afterwebpacker:install:root
- a couple paths will need to be adjusted in the generated tsconfig file.In summary: