Skip to content

Commit 96b685f

Browse files
authored
Update README.md
1 parent 0f20184 commit 96b685f

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@
44
[![npm version][npm-version-img]][npm-link]
55
[![Downloads][npm-downloads-img]][npm-link]
66

7-
A TypeScript custom transformer which helps you achieve reducing your JS bundles by renaming properties aren't exposed to the public.
7+
A TypeScript custom transformer which reduces bundle size (with a help of other tools in your bundler - see below) by renaming properties aren't exposed to the public:
8+
9+
```typescript
10+
function showMessage(opts: { message: string }): void {
11+
alert(opts.message);
12+
}
13+
export function alertMessage(message: string): void {
14+
showMessage({ message });
15+
}
16+
```
17+
18+
goes to:
19+
20+
```javascript
21+
function showMessage(opts) {
22+
alert(opts._internal_message);
23+
}
24+
function alertMessage(message) {
25+
showMessage({ _internal_message: message });
26+
}
27+
exports.alertMessage = alertMessage;
28+
```
29+
30+
_(note that terser/uglify/any other minifier [will rename `_internal_message` property](#how-to-minify-properties) to something like just `s`)_
831

932
You might find the approach pretty similar to how Google Closure Compiler with enabled advanced optimizations works,
1033
but you don't need to refactor your project a lot to make it works for Google Closure Compiler (setting up [tsickle](https://github.com/angular/tsickle) might be hard as well).
@@ -18,15 +41,17 @@ All you need to take all advantages from this tool are:
1841
_This is the next generation of [ts-transformer-minify-privates](https://github.com/timocov/ts-transformer-minify-privates) (which allows you rename the only private class' members),_
1942
_which uses some approaches from [dts-bundle-generator](https://github.com/timocov/dts-bundle-generator) to detect whether some property is accessible via entry points somehow._
2043

21-
## Caution!!!
44+
## How safe renames are
45+
46+
As you might know that you have to pay for everything. The tool was tested on several packages and shows really good results (renames was 100% safe for them), but it doesn't mean that it's 100% safe for your project.
2247

23-
Before start using this transformer in the production, I strongly recommend you check that your code compiles successfully and all files has correct output.
48+
If you rely a lot on duck typing (especially around public level/exports) - it _might_ break your code. But in any way to fix almost all issues I think you can just specify the correct type.
2449

25-
I would say **check the whole project file-by-file** and compare the input with the (expected) output.
50+
I'd suggest everybody who wants to use it in production 1) run all tests you have 2) if it's possible - look at several (or all of them) compiled files in your project and see whether it's good or not.
2651

2752
I cannot guarantee you that the transformer covers all possible cases, but it has tests for the most popular ones, and if you catch a bug - please feel free to create an issue.
2853

29-
Also, it might not work as expected with composite projects, because the project should contain an entry points you set in options, but it might be in other sub-project.
54+
Also, it might not work as expected with composite projects, because the project should contain an entry points you set in [options](#entrysourcefiles), but it might be in other sub-project. So I'd suggest to test it in non-composite project.
3055

3156
## How it works
3257

0 commit comments

Comments
 (0)