-
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
Suggestions on Directory Organization #130
Comments
+1, it is convenient in many cases to work with all the client code in the same directory tree, not to mention not having to have as many jump-up-and-back-down dot-proliferation in relative path references of webpack and package.json files. |
@justin808 Really dig react-on-rails, you've clearly done a ton of thinking and work on these issues 🙂 . Going to chime in with my two-cents anyway though. The way webpacker has it now seems about right to me. Railsy but still compatible with node.js/webpack tooling. Some questions about the centralized client directory approach:
I guess I feel like this is a pretty major departure from the basic approach of the gem so far? Should it maybe be another gem? |
Respect the prior art but I spent a lot of time considering all the options for directory organization and arrived at the current structure following that contemplation.
My core philosophy is that Rails should be structured for the survival pack (see RailsConf 2015). So with a focus on being maximally useful and intuitive to a single full-stack developer.
Now people are of course free to tailor that further to their needs. If you want more of an iron curtain separation, have at it. Rails directories were always just a suggestion.
But I like where we are right now.
… On Feb 27, 2017, at 17:38, Daniel Leavitt ***@***.***> wrote:
@justin808 Really dig your work on react-on-rails, you've clearly done a ton of thinking and work on these issues 🙂 . Going to chime in with my two-cents anyway though.
The way webpacker has it now seems about right to me. Railsy but still compatible with node.js/webpack tooling. Some questions about the centralized client directory approach:
Having a new top-level directory seems like it should be avoided if at all possible
Two package.json files seems kinda weird, right?
Where does stuff build to under this setup? public/client?
Not sure I understand the problem this solves. Can't webstorm/atom/ide users just open the root directory for the project?
I guess I feel like this is a pretty major departure from the basic approach of the gem so far? Should it maybe be another gem?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
With regards to the current directory structure, the most meaningful change would be to consider changing the name of Here are few naming ideas. I'd consider changing the usage of the word "pack" to "bundle" as that's already commonly used in the Webpack space. See #136.
Regardless of changing any default naming, so long as we can configure the locations for:
Then we'll have an easy migration path for Rails 5.0 react_on_rails apps to migrate without huge movements of the files out of the For new React on Rails installs with its generator, I'll do the simplest thing possible, which is to go with whatever is the rails standard. In fact, the yarn and webpacker integration will make the React on Rails install even smoother and easier! I'm excited about that, and I hope to have a PR ready very shortly. |
+1 to Justin's last comment - these changes seem reasonable, helpful improvements, and to not go against any Rails conventions. |
@justin808 At this time I don't see the default changing to being a component-based pitch, but totally happy to see it be configurable. There are people who like component-based structuring of their serverside Rails code as well, and we should certainly be welcoming of that. So 👍 on making whatever configuration points we need such that you can go with a component-based structure for your plugin and projects. |
@dhh Would you be open to having a top level YAML file in a rails project that could allow some of these directory customizations. Something like And then, going forward, we can have this file contain any custom directory mappings and common scripts for tools like Webpacker and React on Rails. Off the top of my head, the directories and scripts that need the mapping are:
Once I get into the modifications, I'll better be able to specify what needs to go into the Having a YML file will make configuration easier and more obvious than using environment variables for things that are project specific. |
I don't think we need a new configuration file to accomplish this. We already have a good configuration system that has worked well enough for configuring the asset pipeline as well. So let's just extend that. What are the alternative placements that you have in mind for node_modules or config/webpack? |
I think it would be nicer if scripts (like the webpack configs) do not have to parse Ruby code. A more generic configuration readable by both the webpack and ruby config files is either JSON or YAML. How about we allow some optional overrides from the defaults in
We have a large base of production apps that are on the standard of putting all webpack related items to be quarantined in How about if I made a PR where the directory names have the current defaults but can be overridden in /package.json, and the webpacker scripts will check on that?
I'm not sure if the location of the
|
I see. I'm not sure this adds that much over just changing the webpacker binstubs, for example. The code is generated, not hidden inside of Rails, so it's all there for the changing. The same goes for the webpack configs themselves. I was more thinking if there are any configs within Rails, like for the view helpers, that need specialization, we can provide options for that. But otherwise I think it's fine for someone to tailor all the generated files. |
Hi @dhh! I'd like to see any yaml or json standard place for a configuration that is not environment specific. The reason is that with JavaScript files, it's quite inconvenient to have to write a ruby binstub script to read a ruby configuration file and to then put whatever value into some environment values. Current Ruby Wayruby-config ==> parsing or loading ==> set env value before calling JS file Proposed wayJS file (and Ruby files) read a standard JSON OR YAML configuration DetailsWe could have a simple configuration file (or use the Plus, I think there's an expectation that env specific files like While any gem can create their own standard configuration (as we did by putting EVERYTHING JavasScript under For example, consider this: # Look into the environment file for a non-commented variable declaration
unless File.foreach(File.join(APP_PATH, RAILS_ENV_CONFIG)).detect { |line| line.match(/^\s*[^#]*config\.x\.webpacker\[\:dev_server_host\].*=/) }
puts "Warning: if you want to use webpack-dev-server, you need to tell Webpacker to serve asset packs from it. Please set config.x.webpacker[:dev_server_host] in #{RAILS_ENV_CONFIG}.\n\n"
end This could be checking if a value is configured in the YAML or JSON file. |
An example of the json suggestion is being implemented by @gauravtiwari in #153. It looks like a great direction based on the code. For example, to read a setting: const { webpacker } = require('../../package.json').config
const distDir = webpacker.distDir From https://github.com/rails/webpacker/pull/153/files#diff-67f77b829953e34e910db8d7c0c285c3R9 |
@justin808 We can close this one. #153 is now merged that addresses this |
I'd suggest that webpacker follow the JavaScript, CSS, Images, Fonts organization that we've used for React on Rails. It's really quite simple:
/client
Over the past 1.5+ years, we've found this setup to be extremely popular with our community. This setup has several advantages:
/client
directory. Under the current structure, one open the "javascript" folder, but then several key files, such as thepackage.json
,node_modules
, and webpack configs are not accessible./client
directory.postinstall
script will dig into the/client
directory and runyarn
.Possibly, the server side could eventually go under
/server
so the number of top level directories is minimal.https://github.com/gauravtiwari/webpacker-example-app
The text was updated successfully, but these errors were encountered: