-
-
Notifications
You must be signed in to change notification settings - Fork 633
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
Enhance asset symlinking for webpack assets #479
Enhance asset symlinking for webpack assets #479
Conversation
@alleycat-at-git Please review. Dev mode worksforeman start -f Procfile.static then go to http://localhost:3000/css_images_fonts production does notRAILS_ENV=production rake assets:precompile
rails s -e production then go to http://localhost:3000/css_images_fonts |
@alleycat-at-git it's a bad thing that tests are passing when this change is not working. Bonus points if you can see a way to test the correct behavior. Another issue is webpack 1.0 vs. 2.0. Possibly we should be doing this differently for webpack 2.0? and only supporting 2.0 with this PR? |
@justin808 I added a commit that fixes the problems. Didn't have time for bonuses - sorry ) Note that you have to use
To run in production mode without nginx and friends Reviewed 28 of 30 files at r1, 2 of 2 files at r2. lib/react_on_rails/configuration.rb, line 12 [r2] (raw file):
We have to be careful here - there are two configs - one in the gem and another in the app. While we have full control over the gem configuration, the point of risk is that app uses old config value - and that's where we put deprecation notice. Do we have access to app config via spec/dummy/config/secrets.yml, line 23 [r2] (raw file):
Is this and intentional one? spec/dummy/config/initializers/assets.rb, line 17 [r2] (raw file):
This one includes not only folders, but subfolders as well spec/dummy/config/initializers/assets.rb, line 30 [r2] (raw file):
I have no idea why - but for some reason pipeline didn't touch those in custom dir. This line solved it Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. spec/dummy/config/initializers/assets.rb, line 17 [r2] (raw file):
|
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. lib/react_on_rails/configuration.rb, line 12 [r2] (raw file):
spec/dummy/config/secrets.yml, line 23 [r2] (raw file):
|
why are we switching from symlinks to copying? What about cleanup of stale asset files? This was handled elegantly via symlinks because they know when they are broken Reviewed 28 of 30 files at r1, 2 of 2 files at r2. .rubocop.yml, line 54 [r2] (raw file):
that's one way to pass the linters lib/react_on_rails/configuration.rb, line 67 [r2] (raw file):
we may also want to put lib/tasks/assets.rake, line 114 [r2] (raw file):
are you putting in any code to delete the files you've copied to the assets file if they are stale? spec/dummy/client/webpack.client.base.config.js, line 63 [r2] (raw file):
?? spec/dummy/client/app/assets/fonts/OpenSans-Light.svg, line 1 [r2] (raw file):
why are we adding 1000 lines of font svg code, we already have svgs we are testing, I would delete this spec/dummy/config/initializers/assets.rb, line 17 [r2] (raw file):
|
Review status: all files reviewed at latest revision, 10 unresolved discussions, some commit checks failed. .rubocop.yml, line 54 [r2] (raw file):
|
5a26a61
to
40c442f
Compare
@robwise, @alleycat-at-git Please review, especially Review status: 9 of 24 files reviewed at latest revision, 10 unresolved discussions. Comments from Reviewable |
Reviewed 21 of 25 files at r3. docs/additional-reading/rails-assets.md, line 56 [r3] (raw file):
lib/tasks/assets.rake, line 67 [r3] (raw file):
ideally we would move all of this functionality into a PORO using the Comments from Reviewable |
Standard Rails does print the fingerprinting, so we should also print the symlinking. I'm OK with skipping the indication that files didn't change. |
I suspect that would be possible but unlikely. The file-loader does this MD5 name by default. |
Review status: all files reviewed at latest revision, 12 unresolved discussions. docs/additional-reading/rails-assets.md, line 56 [r3] (raw file):
|
Review status: all files reviewed at latest revision, 12 unresolved discussions. spec/dummy/client/webpack.client.base.config.js, line 63 [r2] (raw file):
|
40c442f
to
98e2076
Compare
Reviewed 1 of 1 files at r4. lib/tasks/assets.rake, line 27 [r4] (raw file):
I think there were problems with this exact line. If we are in a root assets folder ( Comments from Reviewable |
Review status: all files reviewed at latest revision, 13 unresolved discussions. lib/tasks/assets.rake, line 27 [r4] (raw file):
|
You suspect that what it does by default would be possible but unlikely? Review status: all files reviewed at latest revision, 13 unresolved discussions. docs/additional-reading/rails-assets.md, line 56 [r3] (raw file):
Ok makes sense then
but there's lib/tasks/assets.rake, line 114 [r2] (raw file):
|
Review status: all files reviewed at latest revision, 10 unresolved discussions. spec/dummy/config/initializers/assets.rb, line 17 [r2] (raw file):
|
Comments from Reviewable |
Actually, @robwise is right. https://github.com/webpack/file-loader#filename-templates HOWEVER, should we just document that we don't support that for now? And just list that as an issue (and an exercise for the next react_on_rails contributor)? @alexfedoseev Any opinion? Review status: all files reviewed at latest revision, 10 unresolved discussions. Comments from Reviewable |
BTW, I think the problem that @alleycat-at-git ran into in terms of using a file path for an image in JSX could have been solved by following one of the examples here: https://github.com/webpack/file-loader#examples. Overall, I say we document this design decision and indicate that somebody that wants this can submit a PR to add this enhancement. Review status: all files reviewed at latest revision, 10 unresolved discussions. Comments from Reviewable |
It's already automatically supported and is currently being used on F&G in production. Whether or not webpack fingerprints its assets is its own business that it knows how to deal with via the file and url loaders, we just need to make sure Rails doesn't get in the way by fingerprinting them again (or more accurately, that we have symlinks without the rails fingerprint in the filename). Since we can't rely on Rails's fingerprinting, it's definitely a best practice to have webpack fingerprint assets since that are being referenced by the file/url loaders so that their caches will be properly busted. Review status: all files reviewed at latest revision, 8 unresolved discussions. Comments from Reviewable |
@robwise by "that", I mean subdirectories. I'll see if there's an easy fix to allow that. Review status: all files reviewed at latest revision, 8 unresolved discussions. Comments from Reviewable |
@robwise @alleycat-at-git Easier to fix the issue than doc it. |
I moved the rake code to a module. |
|
||
# require "tmpdir" | ||
# require "tempfile" | ||
|
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.
@samnang @mapreal19 What's the best way to write these tests given the dependencies on the Rails and ReactOnRails config values? I"m thinking of using tmpdir and tempfile, along with some sort of way to set the the global config values temporarily.
And if we make files for test in a tempdir, we don't need to cleanup, right?
Review status: 22 of 27 files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. spec/dummy/config/initializers/react_on_rails.rb, line 86 [r2] (raw file):
|
Review status: 22 of 27 files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. spec/dummy/client/app/assets/fonts/OpenSans-Light.svg, line 1 [r2] (raw file):
|
Review status: 22 of 27 files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. spec/react_on_rails/assets_precompile_spec.rb, line 6 [r6] (raw file):
|
@justin808 oh, according to what Alexey told me that's already supported as well though; you just don't reference it in your JS code with the nesting because the symlinks flatten everything. But it's a bad practice to be putting assets you need for webpack into your rails assets, especially since this means you cannot cache them, so that doesn't make sense to me. Why wouldn't you just put it in your client folder like normal? A totally different, more likely issue is that someone who has rails assets that have identical filenames but are in different folders, when we symlink to a flat structure, those symlinks will have identical filenames and therefore you will have some type of naming collision. This could be avoided one of two ways:
Review status: 22 of 27 files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. spec/dummy/config/initializers/react_on_rails.rb, line 86 [r2] (raw file):
|
Review status: 22 of 27 files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. spec/react_on_rails/assets_precompile_spec.rb, line 6 [r6] (raw file):
|
277f33b
to
0d75282
Compare
Reviewed 1 of 4 files at r6. spec/react_on_rails/assets_precompile_spec.rb, line 6 [r6] (raw file):
|
0d75282
to
fcde037
Compare
@mapreal19 @samnang last commit should make testings much easier. Agree? Review status: 22 of 27 files reviewed at latest revision, 9 unresolved discussions, some commit checks failed. Comments from Reviewable |
I'll be pulling #490 in for the test. Thanks @dzirtusss . |
48cb445
to
06ebd42
Compare
* Better messages when creating symlinks * Updated documentation * Enhanced example * Support subdirectories with webpack assets * Move logic for assets code to service object * Using defaults of the env settings or else values for directories and regexp can be provided.
symlink tests with tempfs
06ebd42
to
a6e35fe
Compare
commit 7d4e7fe Merge: cb9fab4 3c0e6d9 Author: eacaps <[email protected]> Date: Mon Aug 1 11:46:35 2016 -0400 Merge branch 'feature/no-request-context' of github.com:eacaps/react_on_rails into feature/no-request-context commit cb9fab4 Author: eacaps <[email protected]> Date: Thu Jul 21 13:23:51 2016 -0400 allow component rendering in contexts without requests allow custom_context even without request added broken test added fixes to allow actionmailer test to pass cleaned up rubocop warnings resolved some reviewed suggestions updated with proper handles for inMailer added inMailer to test added inMailer checks for test cleaned up rubocop suggestions a few final minor tweaks commit 3c0e6d9 Merge: 5637162 63436ab Author: eacaps <[email protected]> Date: Mon Aug 1 10:44:59 2016 -0400 Merge branch 'master' into feature/no-request-context commit 5637162 Author: eacaps <[email protected]> Date: Mon Aug 1 10:35:40 2016 -0400 a few final minor tweaks commit 63436ab Merge: b4cdfd2 d694df8 Author: Justin Gordon <[email protected]> Date: Sun Jul 31 23:01:59 2016 -1000 Merge pull request shakacode#491 from samphilipd/master Add support for single digit version strings, closes shakacode#489 commit d694df8 Author: Sam Davies <[email protected]> Date: Wed Jul 27 10:52:49 2016 +0100 Add support for single digit version strings, closes shakacode#489 commit b4cdfd2 Author: Justin Gordon <[email protected]> Date: Sun Jul 31 21:25:57 2016 -1000 Update README.md commit 8824b88 Merge: e449d84 442dcd4 Author: Justin Gordon <[email protected]> Date: Sun Jul 31 21:25:35 2016 -1000 Merge pull request shakacode#503 from markpenovich/master fixed spelling error commit 442dcd4 Author: Mark Penovich <[email protected]> Date: Sun Jul 31 23:47:20 2016 -0500 fixed spelling error in readme commit e449d84 Merge: 95efecd 8cec9cf Author: Justin Gordon <[email protected]> Date: Sun Jul 31 15:49:11 2016 -1000 Merge pull request shakacode#497 from shakacode/justin808-skip-docker Remove docker from CI tests .travis.yml commit 95efecd Merge: 46ecf59 ef08742 Author: Justin Gordon <[email protected]> Date: Sun Jul 31 15:48:51 2016 -1000 Merge pull request shakacode#502 from shakacode/move-contributing-to-top-level Move CONTRIBUTING.MD to project top level commit ef08742 Author: Justin Gordon <[email protected]> Date: Sun Jul 31 15:06:11 2016 -1000 Move CONTRIBUTING.MD to project top level This seems to make it show more prominently when making new issues or PRs. commit 46ecf59 Merge: cdb246b a6e35fe Author: Justin Gordon <[email protected]> Date: Sun Jul 31 15:42:20 2016 -1000 Merge pull request shakacode#479 from shakacode/alleycat-at-git-alexey/replace_symlinks_copy * Enhancements to webpack asset preparation * Better messages when creating symlinks * Updated documentation * Enhanced example * Support subdirectories with webpack assets * Move logic for assets code to service object * Using defaults of the env settings or else values for directories and regexp can be provided. commit 8cec9cf Author: Justin Gordon <[email protected]> Date: Fri Jul 29 15:34:10 2016 -1000 Remove Docker from setup * Update .travis.yml * Remove Dockerfile_tests and docker-compose.yml commit a6e35fe Author: dzirtusss <[email protected]> Date: Tue Jul 26 18:43:20 2016 +0300 Update assets_precompile_spec.rb symlink tests with tempfs commit 07a6e48 Author: Justin Gordon <[email protected]> Date: Sun Jul 17 23:23:03 2016 -1000 Enhancements to webpack asset preparation * Better messages when creating symlinks * Updated documentation * Enhanced example * Support subdirectories with webpack assets * Move logic for assets code to service object * Using defaults of the env settings or else values for directories and regexp can be provided. commit cdb246b Author: Justin Gordon <[email protected]> Date: Sat Jul 30 12:30:33 2016 -1000 Doc Fixes (shakacode#499) * Update node-server-rendering.md * Update README.md commit 1e4c0ed Author: Justin Gordon <[email protected]> Date: Sat Jul 30 11:16:25 2016 -1000 Update README.md commit 13f2cf0 Author: Justin Gordon <[email protected]> Date: Thu Jul 28 13:38:29 2016 -1000 Update server-rendering-tips.md (shakacode#494) Update server-rendering-tips.md and README.md commit 0604006 Merge: 8ca86ed e69480a Author: Justin Gordon <[email protected]> Date: Wed Jul 27 22:14:17 2016 -1000 Merge pull request shakacode#492 from cubadomingo/patch-1 Fixes typo commit e69480a Author: Devin Osorio <[email protected]> Date: Wed Jul 27 22:34:13 2016 -0400 Fixes typo commit 566d62f Author: eacaps <[email protected]> Date: Mon Jul 25 12:59:44 2016 -0400 cleaned up rubocop suggestions commit e24fb9f Author: eacaps <[email protected]> Date: Mon Jul 25 11:28:56 2016 -0400 added inMailer checks for test commit eb6e700 Author: eacaps <[email protected]> Date: Mon Jul 25 11:14:41 2016 -0400 added inMailer to test commit 8d34353 Author: eacaps <[email protected]> Date: Mon Jul 25 10:41:35 2016 -0400 updated with proper handles for inMailer commit 52f0cbb Merge: 840bc62 8ca86ed Author: eacaps <[email protected]> Date: Mon Jul 25 10:27:23 2016 -0400 Merge branch 'master' into feature/no-request-context commit 8ca86ed Merge: 9a8b54f 0257cae Author: Justin Gordon <[email protected]> Date: Fri Jul 22 21:35:57 2016 -1000 Merge pull request shakacode#487 from jooohn/fix/typo-in-readme fix(typo) remove duplicated word in readme commit 0257cae Author: jooohn <[email protected]> Date: Sat Jul 23 13:12:37 2016 +0900 fix(typo) remove duplicated word in readme commit 840bc62 Author: eacaps <[email protected]> Date: Fri Jul 22 09:57:28 2016 -0400 resolved some reviewed suggestions commit 9b958fb Merge: 6fdb73a 9a8b54f Author: eacaps <[email protected]> Date: Fri Jul 22 09:56:35 2016 -0400 Merge branch 'master' into feature/no-request-context commit 9a8b54f Merge: e6afa98 4890486 Author: Justin Gordon <[email protected]> Date: Thu Jul 21 17:42:32 2016 -1000 Merge pull request shakacode#483 from shakacode/justin808-inaccurate-build-test-message Update ensure_assets_compiled.rb commit 6fdb73a Author: eacaps <[email protected]> Date: Thu Jul 21 16:35:42 2016 -0400 cleaned up rubocop warnings commit d99fc36 Author: eacaps <[email protected]> Date: Thu Jul 21 14:46:20 2016 -0400 added fixes to allow actionmailer test to pass commit 05d3144 Author: eacaps <[email protected]> Date: Thu Jul 21 14:31:19 2016 -0400 added broken test commit 610906e Author: eacaps <[email protected]> Date: Thu Jul 21 13:25:42 2016 -0400 allow custom_context even without request commit 1e9d58c Author: eacaps <[email protected]> Date: Thu Jul 21 13:23:51 2016 -0400 allow component rendering in contexts without requests commit 4890486 Author: Justin Gordon <[email protected]> Date: Wed Jul 20 19:55:39 2016 -1000 Update ensure_assets_compiled.rb
This change is