Skip to content

Commit

Permalink
Merge branch 'master' of github.com:klesun/ts-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
klesun committed Aug 15, 2024
2 parents 68e595a + e1024b3 commit cc1e57d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Usage: ([sample project](https://klesun.net/entry/midiana/))
```
```typescript
// index.ts
import {makePanel} from './utils/SomeDomMaker';
import {makePanel} from './utils/SomeDomMaker.ts';

export default (composeCont) => {
composeCont.appendChild(makePanel());
Expand Down Expand Up @@ -46,6 +46,18 @@ ________________

I highly recommend you to also use the [@typescript-eslint/consistent-type-imports](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/consistent-type-imports.md) eslint rule to make sure that no redundant http requests will be performed for type-only imports

If you are using `.tsx` and the load speed is more important than compatibility with plain `tsc` emit for you, then I also suggest to set [`allowImportingTsExtensions`](https://www.typescriptlang.org/tsconfig/#allowImportingTsExtensions) to `true` in `compilerOptions` of your `tsconfig.json` and to install [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) with following configuration:
```json
"import/extensions": ["error", {
"ts": "always",
"tsx": "always",
"js": "always",
"jsx": "always"
}],
```
This will enforce `.ts`/`.tsx` extensions in your imports allowing the compiler to know exactly what file to fetch instead of probing all possible extensions - that basically reduces the number of http requests by half, especially crucial on cellular network.
____________________

The script uses [`typescriptServices.js`](https://github.com/microsoft/TypeScript/blob/master/lib/typescriptServices.d.ts) to parse ts file for dependencies and transpile it to js.

Each file loads about 10-50 milliseconds. Some basic optimization is applied during compilation, like using [web workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) and storing compilation results in [`window.localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage), not sure if it can be optimised further, [would need research](https://github.com/klesun/ts-browser/issues/8).
Expand Down

0 comments on commit cc1e57d

Please sign in to comment.