Skip to content

refactor(v2): TS config update: reduce the size of npm modules#4375

Merged
slorber merged 6 commits intofacebook:masterfrom
RDIL:typescript-bundle-improvements
Mar 17, 2021
Merged

refactor(v2): TS config update: reduce the size of npm modules#4375
slorber merged 6 commits intofacebook:masterfrom
RDIL:typescript-bundle-improvements

Conversation

@RDIL
Copy link
Copy Markdown
Contributor

@RDIL RDIL commented Mar 9, 2021

Signed-off-by: Reece Dunham me@rdil.rocks

Motivation

Right now, @docusaurus/core is 1.36mb, which seems a bit big for just the core files. This reduces the size of a number of the packages by doing a number of things:

  • Updates the TypeScript target to ES2019 from ES2017, since Node 12 is now the required minimum for D2. This means that some modern syntax features don't need to be polyfilled.
  • Changes the TypeScript compiler settings to avoid writing out helper functions like this just to use the spread operator:
__rest = function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function") {
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    }
    return t;
};

To instead just import it from tslib, reducing code duplication.

  • Disabling the generation of source maps from .d.ts files, which is just unneeded since the .d.ts are generated in the first place. They are essentially their own source maps.
  • Update TypeScript to v4.1.5

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Everything appears to be fine.

Related PRs

n/a

@RDIL RDIL requested review from lex111 and slorber as code owners March 9, 2021 16:20
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 9, 2021
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 9, 2021

[V1] Deploy preview success

Built with commit 10502d3

https://deploy-preview-4375--docusaurus-1.netlify.app

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 9, 2021

Deploy preview for docusaurus-2 ready!

Built with commit 10502d3

https://deploy-preview-4375--docusaurus-2.netlify.app

@armano2

This comment has been minimized.

@RDIL
Copy link
Copy Markdown
Contributor Author

RDIL commented Mar 10, 2021

@armano2 I actually was looking into this, but honestly I just wanted something that worked. Maybe I'll make something like babel-plugin-transform-tslib-runtime.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 15, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 73
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4375--docusaurus-2.netlify.app/classic/

@slorber slorber added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label Mar 17, 2021
@slorber slorber changed the title feat(v2): Reduce the size of the npm modules refactor(v2): Reduce the size of the npm modules Mar 17, 2021
@slorber slorber changed the title refactor(v2): Reduce the size of the npm modules refactor(v2): TS config update to reduce the size of the npm modules Mar 17, 2021
# Conflicts:
#	packages/docusaurus-plugin-debug/package.json
#	packages/docusaurus-theme-common/package.json
@slorber slorber changed the title refactor(v2): TS config update to reduce the size of the npm modules refactor(v2): TS config update: reduce the size of npm modules Mar 17, 2021
Copy link
Copy Markdown
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@slorber slorber merged commit 76c0b11 into facebook:master Mar 17, 2021
@RDIL RDIL deleted the typescript-bundle-improvements branch March 17, 2021 15:26
@RDIL
Copy link
Copy Markdown
Contributor Author

RDIL commented Mar 17, 2021

This reduces the size of the core to 803 kilobytes, a save of 1.1 megabytes 🎉 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: polish This PR adds a very minor behavior improvement that users will enjoy.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants