πŸ“¦ pi0 / tslite

πŸͺΆTypescript but %60 smaller

β˜… 109 stars β‘‚ 0 forks πŸ‘ 109 watching
πŸ“₯ Clone https://github.com/pi0/tslite.git
HTTPS git clone https://github.com/pi0/tslite.git
SSH git clone git@github.com:pi0/tslite.git
CLI gh repo clone pi0/tslite
renovate[bot] renovate[bot] chore(deps): update autofix-ci/action digest to 7a166d7 (#25) ba8c834 25 days ago πŸ“ History
πŸ“‚ main View all commits β†’
πŸ“ .github
πŸ“ bin
πŸ“„ .editorconfig
πŸ“„ .gitignore
πŸ“„ .prettierignore
πŸ“„ .prettierrc
πŸ“„ build.ts
πŸ“„ package.json
πŸ“„ pnpm-lock.yaml
πŸ“„ README.md
πŸ“„ renovate.json
πŸ“„ tsconfig.json
πŸ“„ README.md

πŸͺΆ tslite

tslite is a redistribution of typescript package with same public API but much smaller install size: vs

Why?

The 'typescript' package's installation size has significantly increased over time and is now unreasonably large for use as a project dependency.

However, this issue has been on the TypeScript team's radar (microsoft/TypeScript#27891), and with the continuous efforts of @jakebailey and the rest of the TypeScript team to reduce the installation size, there are certain limitations preventing further size reduction.

Nevertheless, we can make further optimizations for end-users. The aim of this package is not to impede TypeScript's core improvements but to offer an alternative distribution tailored for end-users who require TypeScript as a peer dependency in their projects.

How?

Check build.ts for build steps.

Minified

Typescript cannot be officially distributed minified because of preserving stack traces and allowing the package to be patched. However, for normal daily use of typescript, it does not matter unless there is a bug with typescript itself which in this case, we can temporarily switch off tslite. Minifying big JS files has a 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.

More Ideas?

I am thinking about more possible ideas to make typescript lib even smaller. For instance, we can lazily import compiler bits from the network on demand and cache them in a global user file being shared across projects. Ideas and PRs are more 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 and pnpm

Using yarn selective dependency resolutions or pnpm overrides:

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