d.ts files from renaming because those are the typing definitions of external libraries. Scope of MinificationĬurrently, TS-Minify will do property renaming throughout all the files that are passed into it. Otherwise, make sure to have /// at the top of your programs if you are using any external libraries. The minfier does not have access to the tsconfig.json file. d.ts files for libraries used in your program to the minifier so that it can reference the type information for property renaming. If you are using a tsconfig.json file to reference your type definitions, pass in the. The minifier will uniformly rename the properties (which are available for renaming) across all the files that were passed in. d.ts file so that the minifier can use the type information. If you are not explicitly including typings using the reference path syntax in your TypeScript file, please pass in the. RenameProgram accepts TypeScript files and. RenameProgram ( fileNames: string, destination? : string ) Note: If you want all internal sources to contain the same renamings, you should pass the relevant files together through a single pass of the minifier.Īn example of what types are considered external and internal: Internal types also include things like object literal types. Declaring a class Foo in your program tells the minifier that properties on Foo objects are within the renaming scope. Internal types are ones that you, the programmer, have defined yourselves. Typings for the standard library are included in the default library typings, lib.d.ts, which the TypeScript compiler uses during transpilation (it will typecheck your program at compile time) and does not need to be explicitly included. If you are using external libraries, it is imperative that you include their corresponding. This includes objects and functions from the JavaScript standard library, and JavaScript libraries like underscore.js or jQuery. TS-Minify is able to safely rename properties by understanding which types are external, and which are not, to one's program.Īn external type is something that you are bringing into your program. Does the property name belong to the DOM?.Does the property belong to a standard built-in object?.Does the property belong to an object declared in an external file (.The renaming eligibility of a property takes several factors into consideration: A “renaming” global map is created with mappings from the original property name to the new generated property name so that re-namings are kept consistent between properties with the same names.Īn example of some mappings from the original property name to the shorter, generated property name. after determining their renaming eligibility. Identifiers that might be considered properties (such as identifiers in property declarations, property access expressions, method names in method declarations, etc.) are renamed to short names such as a, b, etc. The TypeScript Compiler API is utilized in order to access the Abstract Syntax Tree of a TypeScript source file. As such, TS-Minify requires a program to be correctly and throughly typed, otherwise, unwanted renaming may occur. TS-Minify specifically targets property renaming since it is something that is difficult to achieve safely without type information. are taken care of by tools such as UglifyJS. Minification tactics like whitespace removal, dead code removal, variable name mangling, etc. TS-Minify only targets property renaming. This diagram demonstrates TS-Minify's role in the intended minification pipeline. To achieve code size reduction, TS-Minify uses the idea of property renaming: take a TypeScript source file and rename properties to shorter property names, then re-emit the file as valid TypeScript. The impetus for this tool was to reduce the code size of the Angular 2 bundle, but TS-Minify is meant to be a generic tool that can be used on programs written in TypeScript. This contributes to a better user experience. In comparison, Angular 1.4 is about 50kb, minified and compressed.Ī smaller bundle size means that less data needs to be transferred and loaded by the browser. Table of ContentsĪngular 2 (which is written in TypeScript) currently sits at around 135kb after being Uglified and compressed through GZIP. There is currently no CLI or build-tool integration for TS-Minify. This tool is developed on TypeScript and NodeJS, and transpiled to ES5 it uses the CommonJS module system. TS-Minify is tool to aid in the reduction of code size for programs written in the TypeScript language.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |