Skip to content

Commit 0f20184

Browse files
committed
Updated readme
1 parent cbac7f1 commit 0f20184

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

README.md

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

7-
A TypeScript custom transformer which renames all properties if they aren't exported from entry point (in any way) and imported from external package.
7+
A TypeScript custom transformer which helps you achieve reducing your JS bundles by renaming properties aren't exposed to the public.
88

9-
It might help you better minify your bundles with any existing minifier/uglify tool which supports properties mangling.
9+
You might find the approach pretty similar to how Google Closure Compiler with enabled advanced optimizations works,
10+
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).
1011

11-
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),
12-
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.
12+
All you need to take all advantages from this tool are:
13+
14+
1. [Install it](#installation)
15+
1. [Setup your compiler to use it](#how-to-use-the-custom-transformer)
16+
1. [Setup the tool you use to minify/uglify to mangle properties](#how-to-minify-properties)
17+
18+
_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),_
19+
_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._
1320

1421
## Caution!!!
1522

@@ -21,6 +28,15 @@ I cannot guarantee you that the transformer covers all possible cases, but it ha
2128

2229
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.
2330

31+
## How it works
32+
33+
For every property the tool tries to determine whether a property is accessible from entry points you specified in the [options](#entrysourcefiles).
34+
35+
The property is "accessible from entry point" if the type where this property is declared (including all base classes/interfaces) is directly exported or accessible via entry point
36+
(this approach and algorithms are taken from <https://github.com/timocov/dts-bundle-generator>).
37+
38+
If you rely on duck typing a lot in your project - the tool **MIGHT NOT** and quite possible **WILL NOT** work properly, especially it can't detect if the property is exported (because it uses the only explicit "inheritance/usage tree").
39+
2440
## Example
2541

2642
Let's say we have the following source code in entry point:
@@ -46,8 +62,6 @@ export function getOptions(fooBar: number): Options {
4662
After applying this transformer you'll get the next result:
4763

4864
```javascript
49-
"use strict";
50-
Object.defineProperty(exports, "__esModule", { value: true });
5165
function getOptions(fooBar) {
5266
var result = { fooBar: fooBar };
5367
var internalOptions = { _internal_fooBar: fooBar };
@@ -95,8 +109,6 @@ Here we can a class `Class` which implements an interface `Interface` and a fact
95109
After processing you'll get the next result:
96110

97111
```javascript
98-
"use strict";
99-
Object.defineProperty(exports, "__esModule", { value: true });
100112
var Class = /** @class */ (function () {
101113
function Class() {
102114
this.publicProperty = 123;
@@ -133,15 +145,6 @@ More examples you can see [in test-cases folder](https://github.com/timocov/ts-t
133145
1. Install the package `npm i -D ts-transformer-properties-rename`
134146
1. Add transformer with [one of possible ways](#how-to-use-the-custom-transformer)
135147

136-
## How it works
137-
138-
For every property the tool tries to understand whether a property is accessible from entry points you specified in the [options](#options).
139-
140-
The property is "accessible from entry point" if the type where this property is declared (including all base classes/interfaces) is directly exported or accessible via entry point
141-
(this approach and algorithms are taken from <https://github.com/timocov/dts-bundle-generator>).
142-
143-
If you use duck typing a lot in your project - the tool **WILL NOT work properly**, especially it can't detect if the property is exported (because it uses the only inheritance tree).
144-
145148
## Options
146149

147150
### entrySourceFiles

0 commit comments

Comments
 (0)