-
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
Proposal to merge in changes from Webpacker Lite. #464
Comments
I like the single string. I'd suggest calling it
We're generally not keen on using ENV as a default/primary configuration mechanism. Beyond that note, some way to configure & override it sounds useful, but I don't have enough context to have an opinion on how it should look. |
@matthewd wrote:
The ENV part is totally optional...Allows having different procfiles for using static assets vs. hot loading. And regarding the @gauravtiwari We've got one vote for the simpler, non-nested, 4 key approach. |
@justin808 Awesome. Lets make this work 👍 🍰 YML configThe reasons why the dev server config is nested and broken into different keys are:
Helpers
I agree it's trivial to do but we wanted to keep things simple. Now, it's responsibility of Webpack and plugins to return fully qualified asset paths based on environment instead of mixing responsibilities and logic. Happy to hear more thoughts on this :)
development:
public_output_path: packs
dev_server:
host: 0.0.0.0
port: 8080
hot: true
https: false
def checksum
files = Dir["#{Webpacker::Configuration. source_path}/**/*", "package.json", "yarn.lock"].reject { |f| File.directory?(f) }
files.map { |f| File.mtime(f).utc.to_i }.max.to_s
end
Rails.cache.fetch(["webpacker", "manifest", checksum]) do
# .... compile code
end What do you think? |
@gauravtiwari, in order for us to agree on the result, we have to first agree on goals. Common GoalsReact on Rails needs these 2 things:
Migration for React on Rails AppsIn order to make any migration for existing React on Rails users to use Webpacker from Webpacker Lite, I'd suggest the following are mandatory, along with the migration steps for React on Rails apps:
References from React on Rails
Action PlanIf we can agree on these, my action plan would be:
|
@justin808 Sounds good 👍 with one exception i.e. webpack config. You see, webpacker is all about webpack and therefore, we can't do much there - the idea is to keep it simple and production ready much like Sprockets. As discussed earlier, the best route is - you ship your own version of webpack config like you have been doing so far for We can merge in hot reloading changes but without using environment and instead use dedicated config option inside Happy to help out with these changes 👍 😄 Doesn't look like a lot though |
@gauravtiwari Your suggestions are not clear to me. I'd like to have React on Rails depend on Webpack so that:
Please see my message above again and comment on it line by line. |
@kaspth @gauravtiwari @dhh Any feedback on this? I'm giving a number of talks around the US on React on Rails and everybody is interested in how Webpacker relates to React on Rails. I'd prefer if React on Rails could depend on Webpacker so long as the simple part that React on Rails needs could remain stable. |
@justin808 Lets go over this together step by step. Goal
React on Rails current setup
Minimal steps to integrate with WebpackerSince I feel the most straightforward path is:
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
development:
# https://github.com/shakacode/react_on_rails/blob/master/lib/generators/react_on_rails/templates/base/base/config/webpacker_lite.yml#L17
# Instead of - hot_reloading_enabled_by_default
dev_server:
hot: true Just make sure the core settings are there for webpacker, which are paths and
def stylesheet_pack_tag(name, **options)
return nil if Webpacker::DevServer.hot?
stylesheet_link_tag(Webpacker::Manifest.lookup("#{name}#{compute_asset_extname(name, type: :stylesheet)}"), **options)
end
Webpacker considers React on Rails on the other hand appends I am not sure what cons are to approach Webpacker is using? Feel free to point out. In summary following changes are required to make the migration possible: React on Rails
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
development:
# instead of - hot_reloading_enabled_by_default
dev_server:
hot: true
Webpacker
Does this makes sense? |
@gauravtiwari please read my discussion above again. My original position stands on this. |
@justin808 Sure
|
Good! the Ruby code can even support both keys. Your JS code only needs the "packs" style keys.
The current Rails manifest does not put in URLs. The default for Webpack does not do this. Semantically, the manifest is a mapping of basic names to hashed names. Why should the manifest care what the web server is doing. The comment I got over and over again was something along the lines of "this makes no sense to put URLs in the manifest". Note, React on Rails does not require any sort of webpack config. While we generate a super simple example, that is just an example. More importantly, why should React on Rails, as a framework, put additional, unnecessary requirements on the usage? Both Webpacker and React on Rails should place the absolute minimum requirements on our users. To that ends, just use one field for the "host" in the YAML file ("host" is semantically wrong currently according to the MDN docs for URL). Our libraries should do the extra work of parsing the host (it's easy. Before we can move forward, we all need to agree on the last point: |
@justin808 Great 👍
Basically, there are no additional requirements for user - it's all standard webpack. |
While that's reasonable, I'd argue that MDN is more official. Are we strongly objecting to simplifying to alternately supporting a non-nested host which can optionally include https and a port?
Do you have data on any large projects? My company ShakaCode has worked on many large projects and we have not found this to be the case. In fact, we NEED to use the Webpack DLL plugin for development. This may still be possible.
I'd recommend that (per my note above):
|
@justin808 - I don't see the desire to change the name and change the config file as you suggest. I agree with @gauravtiwari here. Yes, it would make it easier for you to write migration instructions for React on Rails consumers to upgrade but I think you can easily build that into a script/Rake task as well and consumers will not know the difference. Once it is set, this will never change for consumer so why force a large change like this on other consumers of Webpacker? To me, the perceived benefit does not outweigh the cost of making a breaking change for something this trivial. |
I do agree with having an option for the manifest to contain relative paths and not full URLs. Also, allowing ENV variables to override certain configs that change across different deployment environments is good especially for Docker deployments where you want to generate one image but flex config without having to rebuild the container. |
On more thought with regard to the last comment about ENV variables, I think you can reference the ENV variables in the YML files if the system parsing the files passes the file thru ERB. I would have to check Webpack source but it seems like it should be doing it that way. Maybe that is a good compromise? |
Yes. We use ENV references in database.yml as well. Let's stick with that.
… On Jun 14, 2017, at 02:40, Nick Smith ***@***.***> wrote:
On more thought with regard to the last comment about ENV variables, I think you can reference the ENV variables in the YML files if the system parsing the files passes the file thru ERB. I would have to check Webpack source but it seems like it should be doing it that way. Maybe that is a good compromise?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Here is the official recommendation - https://webpack.js.org/guides/development/#choosing-a-tool
If
For webpacker, there is no need because one can pass CLI options and override at run-time. Apart from that all other settings are configurable per environment (just paths). ./bin/webpack-dev-server --host example.com --port 8081 --inline true --hot false Anything else I am missing?
Happy to drop it but from our discussion I haven't found any good reason to do so. In the end it's just manifest, which contains meta data for CDN/Server and asset paths. The setup is simple, implicit and just works. |
Alright just saw this issue - reactjs/react-rails#739 and sounds like a good reason to remove CDN/host information from |
BTW, |
ReactOnRails can provide it the same way react-rails does with webpacker, but webpacker forces you to use a single bundle across the entire app for both server and client rendering, which is very limiting. |
Yes. Under no circumstances do we want to require using a Ruby wrapper around the JavaScript commands. Nobody else in the JS community is going to do this.
@gauravtiwari Where do we stand with what we agree and disagree upon? |
@robwise By default webpacker supports multiple bundles or packs. So one pack could be client rendered and other could be server rendered (isolated i.e. no reference to windows etc.). packs
- app-client.js
- app-server.js outputs two bundles/packs <%= react_component 'app-client' %>
<%= react_component 'app-server', { prerender: true } %> |
Yes, makes sense to not include host information per reactjs/react-rails#739 👍
The idea behind ruby wrapper for # This is env aware and applies all necessary settings for executables
# instead of of passing env values through package.json and then doing the same thing
./bin/webpack-dev-server |
@gauravtiwari This sounds great. Please comment on whether we should have an option or different helper, per this issue: shakacode/webpacker_lite#20 (comment) Here is the readme change, from @robwise https://github.com/shakacode/webpacker_lite/pull/22/files Unmanifested FilesSome special situations may call for including files output by webpack that are not included in the <%# app/views/layouts/application.html.erb %>
<%= unmanifested_javascript_pack_tag('vendor-dll') %>
<%= unmanifested_stylesheet_pack_tag('vendor-dll') %> |
@gauravtiwari I'm starting this one. @robwise and I need to know what to do about the unmanifested files. |
Regarding your dll example, it is possible to use the same file for different webpack builds when using the manifest plugin with the
This way, the plugin will amend lines. If this is the only example for unmanifested files, I think it would be better to not include such functionality, because you also mentioned that it was only for development (btw: I suggest to use the dll plugin in production too, because it is very efficient for long term caching) |
@p0wl You're a genius!!! That manifest caching snippet totally worked! Cheers! We still use a vendor bundle in production, but we switch to doing it via the common chunk plugin instead. At the time we set up our architecture it was still being recommended to only use DLL in development as it was not production-ready. I'm not sure if that's still the case or not. |
@justin808 Lets do what we have discussed earlier first and we can look into dll helper later. |
Yes, DLL needs an additional webpack config. But if @justin808's proposal of "Unmanifested Files" is only needed when using the DLL plugin, I would recommend against it, because I think it is not a good idea to create another possibility for rails to access webpacker files (right now it is ONLY the |
Thanks 👍 Yeah, that makes sense - could be confusing for most users and probably redundant. |
Yeah, I closed that PR since I was able to do it with the caching thing. It does require two configs, yes. We also use a third config for our server rendering bundle as well, although that's for convenience, it technically doesn't have to be done that way. |
@justin808 Hey - Any news on this? |
@gauravtiwari I'm working on this today. I need to do something about #571, skipping the asset host for server rendering. Suggestions? |
@justin808 Can we use this instead? https://github.com/rails/webpacker/blob/master/lib/webpacker/manifest.rb#L24 I think this will return full local path for a given asset. |
@gauravtiwari I think I found a simpler solution (from my original one) Please advise if this small API addition is OK for rails/webpacker. Or maybe we don't need in the view helper? and we can call the manifest method? I'll save that for the merge. Please advise. |
@justin808 Since we are going to use this internally we can use |
I'll need to access lookup_path from React on Rails. I'm guessing this should be feasible. However, we need to document this as part of the public API as this affects any other code that is server rendering. |
@justin808 Yepp lets document it. I think |
@gauravtiwari we should organize the files so that anything exposed publicly is more obvious. Otherwise, some "helpful" refactoring will break downstream libraries. Maybe we should have a wrapper class of these public APIs so make the public surface area clear. |
See rails/webpacker#594 From a long discussion on #464, this issue will summarize. I'll soon be posting proposed changes to the README.md. Summary of changes * Move base url out from manifest.json to manifest.rb * Assign env variables to dev server settings so it can be overridden at runtime. * The keys for dev_server should use same format as of now as documented in Paths on the README.md. Note that * hot is a new setting to indicate that the dev_server is used with hot reloading, which means that CSS should be inlined to be hot loaded. The presence of dev_server means that the webpack-dev-server is used for the given env. development: // put the created files to the /public/webpack/development directory public_output_path: webpack/development //# if dev_server is not provided, then dev_server is not used dev_server: hot: true # This is a new setting static: false host: localhost https: false
See rails/webpacker#594 From a long discussion on #464, this issue will summarize. I'll soon be posting proposed changes to the README.md. Summary of changes * Move base url out from manifest.json to manifest.rb * Assign env variables to dev server settings so it can be overridden at runtime. * The keys for dev_server should use same format as of now as documented in Paths on the README.md. Note that * hot is a new setting to indicate that the dev_server is used with hot reloading, which means that CSS should be inlined to be hot loaded. The presence of dev_server means that the webpack-dev-server is used for the given env. development: // put the created files to the /public/webpack/development directory public_output_path: webpack/development //# if dev_server is not provided, then dev_server is not used dev_server: hot: true # This is a new setting static: false host: localhost https: false
We have already merged/added changes discussed here. @justin808 Please open a new issue with remaining issues (if any?) and lets discuss it there. |
Following up from #453 and my discussion with @gauravtiwari, and my article Webpacker Lite: Why Fork Webpacker? and my fork Webpacker Lite.
I'd like to get some consensus on merging in the differences of Webpacker Lite before doing any work on a PR.
YML file and LIVE
Webpacker, from installer file:
Webpacker Lite, from README:
host
should have beenhostname
in webpacker).HOT_RELOADING
public_output_path
rather thanwebpack_public_output_dir
so long as this is the full path within the public directory where the generated files go, minus the/public
part.Helper differences
The text was updated successfully, but these errors were encountered: