Skip to content

Various tweaks to reduce main bundle size#1929

Merged
tdonohue merged 5 commits intoDSpace:mainfrom
atmire:w2p-96252_Reduce-main-bundle-size-part1
Oct 27, 2022
Merged

Various tweaks to reduce main bundle size#1929
tdonohue merged 5 commits intoDSpace:mainfrom
atmire:w2p-96252_Reduce-main-bundle-size-part1

Conversation

@ybnd
Copy link
Copy Markdown
Member

@ybnd ybnd commented Oct 25, 2022

Related to #1921

Description

This PR includes a few ways to reduce the size of the main.js bundle

  • Make the dependencies used by dsMarkdown for Markdown support lazy-loaded in the same way as the MathJax plugin
    (this saves about 80kb)
  • Enforce per-function imports for lodash so it can be properly optimized by tree-shaking
    (this saves about 16kB)
  • Remove the json5 dependency from runtime code; convert i18n files to plain JSON in Webpack instead
    (this saves about 9kB and reduces the size of served i18n files slightly)

Instructions for Reviewers

  • Confirm that the dsMarkdown pipe still works by checking out some Items with Markdown in dc.abstract
  • Confirm that i18n files are now served as plain JSON, and that i18n still works in SSR and CSR
  • Confirm that the added ESLint rule disallows imports like
    import { map, filter } from 'lodash';
    Instead, they'll have to be
    import map from 'lodash/map';
    import filter from 'lodash/filter';

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome). If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes TSLint validation using yarn run lint
  • My PR doesn't introduce circular dependencies
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • If my PR includes new, third-party dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.

@ybnd ybnd force-pushed the w2p-96252_Reduce-main-bundle-size-part1 branch from d03fc00 to bde8419 Compare October 25, 2022 19:02
@ybnd ybnd self-assigned this Oct 27, 2022
@ybnd ybnd added the dependencies Pull requests that update a dependency file label Oct 27, 2022
@ybnd ybnd marked this pull request as ready for review October 27, 2022 16:46
@tdonohue tdonohue self-requested a review October 27, 2022 17:18
@tdonohue tdonohue added 1 APPROVAL pull request only requires a single approval to merge high priority labels Oct 27, 2022
@tdonohue tdonohue added this to the 7.5 milestone Oct 27, 2022
Copy link
Copy Markdown
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks @ybnd !

I tested this in production mode (yarn serve:ssr) and everything is working well for me. I tried an item with Markdown & MathJax and that's still working. I verified the new JSON "compilation" of the i18n scripts is working properly and tested different languages & also tested SSR (by turning off all JS in my browser).

Finally, I verified that, in total, this PR shrinks the main.js by about 100KB gzipped! Great improvements!

@tdonohue
Copy link
Copy Markdown
Member

Merging this immediately as the changes are small, but very important. That way I can also update my main.js reduction PRs as needed after this is merged.

@tdonohue tdonohue merged commit 142dcf5 into DSpace:main Oct 27, 2022
4science-it pushed a commit to 4Science/dspace-angular that referenced this pull request Jul 29, 2024
…pace#1929)

Task/dspace cris 2023 02 x/DSC-1650 davide

Approved-by: Francesco Molinaro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 APPROVAL pull request only requires a single approval to merge dependencies Pull requests that update a dependency file high priority

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants