Open fis-cz opened 8 years ago
You might be interested in our work here: https://github.com/angular/tsickle
That's a project that allows annotating TypeScript source to be compiled with Closure Compiler. Closure Compiler has been around for a while and is overall a very powerful and mature minifier, if occasionally a bit fickle to use. It supports conditional compilation through constant folding (e.g. if (goog.DEBUG) ...
).
You might also want to look into Rollup, which supports some ES6 flattening.
thanks for this, I have been looking for it! Great job!
I am considering to write a TS pre/post processor which should take care of at least following actions:
The preprocessor should be implemented like that:
the preprocessor.ts must be included in the TS project. It will "virtually" pollute the main object with following statements:
If we are talking mainly about minification, something like this would be great:
$LIBRARY = function $LIBRARY(libname: string)
It should take all classes from the same module and put them to the single library file or take classes from various namespaces / modules and make a single library source code file from it. The main reason would be to try to avoid a lot of repetitive namespace/module definitions in the compiled code.I am still looking for the way how to reference minified property by a string so I came with this concept:
$MINIFIEDNAME = function $MINIFIEDNAME(name: string, object: any);
As previous statements are I would say straightforward this one I guess requires deeper explanation. The function returns the original unminified variable/object/property name defined in string but after minification the preprocessor will take the resultant object parameter and will replace whole definition in the code by the minified name. The syntax looks really horrible so I am still trying to find a better way, how to define this in order to look nicer.Let me give you an example:
The Pre-Post processor will be included in the build process like this:
Unminified program -> Preprocessor -> Clean code without DEFS/IFDEFS/LIBRARIES -> Minifier -> Minimized code -> MinPreprocessor -> String names replaced -> Compiler -> Compiled JS and .map to generated lib files -> Postprocessor-> Compiled JS with maps to original source code
It will preprocess all TS files in the project (eventually defined folder walked through recursively) before and after minification step in order to:
Before minification:
Calls minifier to do his job
After minification:
Calls compiler to do his job
Post processing:
Main requirements:
Any comments and recommendations are welcome. Especially ideas, how to exactly implement it in order to be compatible with existing build systems.