Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upReplace sprockets/browserify with Webpack #2617
Conversation
Gargron
added some commits
Apr 29, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Gargron
Apr 29, 2017
Member
@ykzts Unfortunately, jQuery is still a dependency because of jquery-ujs which makes some non-GET links work. There is rails-ujs which is jQuery-free but it didn't work with webpack. jQuery is also used in public.js. On the upside, webpack splits the code into vendor.js and application.js/public.js bundles, so dependencies are not loaded twice.
|
@ykzts Unfortunately, jQuery is still a dependency because of jquery-ujs which makes some non-GET links work. There is rails-ujs which is jQuery-free but it didn't work with webpack. jQuery is also used in public.js. On the upside, webpack splits the code into vendor.js and application.js/public.js bundles, so dependencies are not loaded twice. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ykzts
Apr 29, 2017
Collaborator
@Gargron Uh... As far as I see, jquery-ujs is not used in the part where React is used. Even if you delete it, application.js will run with the exception of the notification.
|
@Gargron Uh... As far as I see, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
The web UI has one logout button which needs jquery-ujs |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Oh... I see. Certainly. I'm sorry. |
Gargron
added some commits
Apr 29, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Gargron
Apr 29, 2017
Member
I don't understand why view specs are failing with this cryptic error. I changed nothing about them...
|
I don't understand why view specs are failing with this cryptic error. I changed nothing about them... |
Gargron
added some commits
Apr 30, 2017
| cascade: true, | ||
| keep_fargs: false, | ||
| warnings: true | ||
| }, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nolanlawson
Apr 30, 2017
Collaborator
Just setting compress to true should be fine, unless there' is something in particular you wanted to tweak here?
nolanlawson
Apr 30, 2017
Collaborator
Just setting compress to true should be fine, unless there' is something in particular you wanted to tweak here?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nolanlawson
Apr 30, 2017
Collaborator
I dunno, most every JS project I know of just uses uglify with mangle and compress set to true. You can tweak the compress settings in rare cases, but in my mind "mangle/compress" (aka uglifyjs -mc) is basically Uglify's "default" setting. :)
nolanlawson
Apr 30, 2017
Collaborator
I dunno, most every JS project I know of just uses uglify with mangle and compress set to true. You can tweak the compress settings in rare cases, but in my mind "mangle/compress" (aka uglifyjs -mc) is basically Uglify's "default" setting. :)
| warnings: true | ||
| }, | ||
| mangle: false, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nolanlawson
Apr 30, 2017
Collaborator
I don't often see mangle set to false, would this break something to turn on?
nolanlawson
Apr 30, 2017
•
Collaborator
I don't often see mangle set to false, would this break something to turn on?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nightpool
May 2, 2017
Collaborator
if mastodon published sourcmaps in prod I would be all about that. I personally like having mangle off otherwise though.
nightpool
May 2, 2017
Collaborator
if mastodon published sourcmaps in prod I would be all about that. I personally like having mangle off otherwise though.
| algorithm: 'gzip', | ||
| test: /\.(js|css|svg|eot|ttf|woff|woff2)$/ | ||
| }) | ||
| ] |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nolanlawson
Apr 30, 2017
Collaborator
It'd be a good idea to also use the DefinePlugin to ensure that NODE_ENV is set to production which cuts out a lot of development-only code in React as well as other libraries (React docs on the subject). I also opened up a PR for doing the equivalent thing in Browserify FWIW: #2635
nolanlawson
Apr 30, 2017
Collaborator
It'd be a good idea to also use the DefinePlugin to ensure that NODE_ENV is set to production which cuts out a lot of development-only code in React as well as other libraries (React docs on the subject). I also opened up a PR for doing the equivalent thing in Browserify FWIW: #2635
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nolanlawson
Apr 30, 2017
Collaborator
Huh that's odd, React's docs still say to add DefinePlugin, but maybe it's no longer necessary for Webpack 2? Just checked the output bundles after asset:precompile and I'm not seeing any NODE_ENV references, so LGTM
nolanlawson
Apr 30, 2017
Collaborator
Huh that's odd, React's docs still say to add DefinePlugin, but maybe it's no longer necessary for Webpack 2? Just checked the output bundles after asset:precompile and I'm not seeing any NODE_ENV references, so LGTM
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nolanlawson
Apr 30, 2017
Collaborator
FWIW, just tested the bundle size, and before this PR application.js is 2.97 MB, afterwards application.js is 563 kB and vendor.js is 1.57 MB, so combined they're 2.14 MB which is a huge reduction. Very nice!
|
FWIW, just tested the bundle size, and before this PR |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Gargron
Apr 30, 2017
Member
Travis keeps breaking because node-sass needs some binaries that apparently don't get cached by Travis?
|
Travis keeps breaking because node-sass needs some binaries that apparently don't get cached by Travis? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Gargron
Apr 30, 2017
Member
Here are upgrade notes:
- Ensure you have Node 6.x and not less
- Install bundle/yarn dependencies
- If it complains about node-sass,
npm rebuild node-sass --force - Make sure
CDN_HOSTcontains protocol part, if you are using it - Precompile, restart
|
Here are upgrade notes:
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
kyzh
Apr 30, 2017
I'm not sure if you are happy for people to provide feedback here.
Feel free to tell me off if you don't think it is appropriate.
This branch is live on glitch.social (thanks Bea).
I've been trying for a while and there is noticeable improvement.
It definitely helps with recent issues I had on mobile #2648
(Edit: typo)
kyzh
commented
Apr 30, 2017
•
|
I'm not sure if you are happy for people to provide feedback here. This branch is live on glitch.social (thanks Bea). (Edit: typo) |
nolanlawson
referenced this pull request
Apr 30, 2017
Closed
Use envify + NODE_ENV=production for smaller JS bundle #2635
mjankowski
referenced this pull request
May 1, 2017
Closed
CLI utility to check coverage of a locale #1742
Gargron
changed the title from
[WIP] Replace sprockets/browserify with Webpack
to
Replace sprockets/browserify with Webpack
May 1, 2017
Gargron
added some commits
May 1, 2017
| @@ -1,6 +1,6 @@ | ||
| body { | ||
| font-family: 'Roboto', sans-serif; | ||
| background: $color1 image-url('background-photo.jpg'); | ||
| background: $color1 url('../images/background-photo.jpg'); |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mjankowski
May 1, 2017
Collaborator
It seems weird that the stylesheets move into app/javascript/... -- is that normal for webpack?
mjankowski
May 1, 2017
Collaborator
It seems weird that the stylesheets move into app/javascript/... -- is that normal for webpack?
| @@ -0,0 +1,11 @@ | ||
| @font-face { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mjankowski
May 1, 2017
Collaborator
Same question here ... it seems weird that the fonts move into app/javascript/... -- is that normal?
mjankowski
May 1, 2017
Collaborator
Same question here ... it seems weird that the fonts move into app/javascript/... -- is that normal?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Gargron
May 1, 2017
Member
It's not normal but if I leave anything in assets it will get picked up by sprockets, I think, and then it would get processed twice.
Gargron
May 1, 2017
Member
It's not normal but if I leave anything in assets it will get picked up by sprockets, I think, and then it would get processed twice.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mjankowski
May 2, 2017
Collaborator
I guess I would have assumed that the JS moves to app/javascript but anything which really is still just a static asset either a) stays in app/assets (and is made available to the JS, where needed? I think webpack does this...?), or b) moves to like - app/fonts or something?
The thing I'm asking about here isn't the move away from sprockets and to webpack, but about the naming convention of having fonts and images in an app/javascript dir...
mjankowski
May 2, 2017
Collaborator
I guess I would have assumed that the JS moves to app/javascript but anything which really is still just a static asset either a) stays in app/assets (and is made available to the JS, where needed? I think webpack does this...?), or b) moves to like - app/fonts or something?
The thing I'm asking about here isn't the move away from sprockets and to webpack, but about the naming convention of having fonts and images in an app/javascript dir...
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Gargron
May 2, 2017
Member
It isn't too weird really, as some React practices involve bundling CSS modules directly with components, e.g. CSS and JS side by side, with any relevant images included. We don't use that but it's still all close together.
Gargron
May 2, 2017
Member
It isn't too weird really, as some React practices involve bundling CSS modules directly with components, e.g. CSS and JS side by side, with any relevant images included. We don't use that but it's still all close together.
| @@ -8,6 +8,6 @@ | ||
| # Precompile additional assets. | ||
| # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. | ||
| Rails.application.config.assets.precompile += %w(application_public.js custom.css) | ||
| # Rails.application.config.assets.precompile += %w(application_public.js custom.css) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Gargron
May 1, 2017
Member
It's commented out by default so I left it commented out instead of deleting
Gargron
May 1, 2017
Member
It's commented out by default so I left it commented out instead of deleting
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mjankowski
May 1, 2017
Collaborator
Should we add a Procfile.dev (for people who use foreman in dev) or bin/server or some other way to include the running of the webpack-dev-server for people to get all in one process alongside the rails server and workers?
|
Should we add a |
Gargron
added some commits
May 2, 2017
Gargron
referenced this pull request
May 2, 2017
Closed
Increase React component spec coverage #2722
Gargron
added some commits
May 2, 2017
mjankowski
approved these changes
May 3, 2017
I'm approving this on the assumption that we continue to find edge cases and work out best practices once the bulk of it is in.
Gargron
merged commit f5bf5eb
into
master
May 3, 2017
Gargron
deleted the
feature-webpack
branch
May 3, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nolanlawson
May 5, 2017
Collaborator
On second analysis, it looks like this didn't shrink the bundle size much.
796K application-6d6d82d4e4776ad9b07e.js
8.0K public-39f8a254bfe861a34311.js
2.0M vendor-5e5fbf294d06423aa79e.js
Looks like we're still at around 2.8MB of JavaScript total. I've run webpack-bundle-analyzer on the latest master branch (4d22d03); here's a live view of the data. A few things jump out at me:
- emojione takes up a ton, hopefully emojione/emojione#489 will get merged soon
- all the various language JSON files take up a lot inside of Mastodon itself
bufferis unnecessary; it's required by an unused API inhttp-link-header- Lodash takes up a bit, worth looking into
lodash-webpack-pluginandbabel-plugin-lodash - Using Rollup, Mastodon's code could be one big index.js instead of many small modules
Mostly I don't see any easy wins here; just need to assiduously go through dependencies and try to remove what's not needed, replace where possible, etc. Code-splitting would also be good. Keep in mind that Sean Larkin from the Webpack team recommends <300KB (without gzip) for each chunk, whereas Addy Osmani on the Chrome team recommends <100KB to hit <3 seconds on 3G.
|
On second analysis, it looks like this didn't shrink the bundle size much.
Looks like we're still at around 2.8MB of JavaScript total. I've run webpack-bundle-analyzer on the latest master branch (4d22d03); here's a live view of the data. A few things jump out at me:
Mostly I don't see any easy wins here; just need to assiduously go through dependencies and try to remove what's not needed, replace where possible, etc. Code-splitting would also be good. Keep in mind that Sean Larkin from the Webpack team recommends <300KB (without gzip) for each chunk, whereas Addy Osmani on the Chrome team recommends <100KB to hit <3 seconds on 3G. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Gargron commentedApr 29, 2017
•
edited
Edited 1 time
-
Gargron
edited Apr 30, 2017 (most recent)
Fix #1712, #1742
What this toolchain upgrade provides:
Untested potential benefits:
TODO:
Development implications:
./bin/webpack-dev-serverat the same time asrails syarn run manage:translationsto get a list of all missing/redundant translations in the web UI