5.3.0-dev.20231006.1 • Published 7 months ago

tslite v5.3.0-dev.20231006.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

💙 tslite

Smaller Typescript Redistibution

Note This is a proof-of-concept work!

Why?

Typescript size has been grown over the time and is unreasonably big today (install size) to be installed as a dependency in projects.

However this issue had been under the radar of typescript team for a long time (microsoft/TypeScript#27891) and constant attempts to reduce the install size by @jakebailey and rest of their team team 💙, there are certain decitions typescript cannot do to reduce size furthor as there is a vast majority of tools and ecosystem that is depending on this package while for user facing public API, we can make more improvements.

How?

Check build.ts for build steps.

Minified

Typescript cannot be officially distributed minified because of preserving stack traces and allowing package to be patched.

However for normal daily use of typescript, it does not really matter unless there is a bug with typescript itself which in this case, we can temporarily switch off tslite.

Minifing big js files has huge impact on the install size. tslite only minifies non lib. files over 250KB using UglifyJS.

Removed Locales

Typescript package ships with ~3.8M of localized translation files for error messages which are usually not used. tslite removed them.

Typescript Nightly

@jakebailey recently worked on microsoft/TypeScript#55273 to merge tsserverlibrary.js and typescript.js and removing huge amount of duplicate codes.

This change will be available as of early 5.3. I wasn't patient enough and made this redist based on this improvement to see the difference. (It reduced minified lib size from ~17MB to ~14MB)

More Ideas?

I am thinking about more possible ideas in order to make typescript lib even smaller. For instance we can lazily import compiler bits from network on demand and cache them in a global user file being shared across projects. Ideas and PRs are mote than welcome!!

Usage

Keep typescript as a devDependency and use resolutions to alias tslite:

npm

Using npm overrides:

// package.json
{
  "overrides": {
    "typescript": "npm:tslite@latest"
  }
}

yarn

Using yarn selective dependency resolutions:

// package.json
{
  "resolutions": {
    "typescript": "npm:tslite@latest"
  }
}

pnpm

Using pnpm.overrides:

// package.json
{
  "pnpm": {
    "overrides": {
      "typescript": "npm:tslite@latest"
    }
  }
}