This repository is a snapshot of a commit on the original repository. The original code used to generate this is located at http://github.com/angular/angular-cli.
We do not accept PRs or Issues opened on this repository. You should not use this over a tested and released version of this package.
To test this snapshot in your own project, use
npm install git+https://github.com/angular/angular-devkit-build-optimizer-builds.gitAngular Build Optimizer contains Angular optimizations applicable to JavaScript code as a TypeScript transform pipeline.
This package is deprecated and should not be used. It has always been experimental (never hit 1.0.0) and was an internal package for the Angular CLI. All the relevant functionality has been moved into @angular-devkit/build-angular.
Transformations applied depend on file content:
- Class fold, Scrub file and Prefix functions: applied to Angular apps and libraries.
- Import tslib: applied when TypeScript helpers are found.
Some of these optimizations add /*@__PURE__*/ comments. These are used by JS optimization tools to identify pure functions that can potentially be dropped.
Static properties are folded into ES5 classes:
// inputvarClazz=(function(){functionClazz(){}returnClazz;})();Clazz.prop=1;// outputvarClazz=(function(){functionClazz(){}Clazz.prop=1;returnClazz;})();Angular decorators, property decorators and constructor parameters are removed, while leaving non-Angular ones intact.
// inputimport{Injectable,Input,Component}from'@angular/core';import{NotInjectable,NotComponent,NotInput}from'another-lib';varClazz=(function(){functionClazz(){}returnClazz;})();Clazz.decorators=[{type: Injectable},{type: NotInjectable}];Clazz.propDecorators={'ngIf': [{type: Input}]};Clazz.ctorParameters=function(){return[{type: Injector}];};varComponentClazz=(function(){functionComponentClazz(){}__decorate([Input(),__metadata('design:type',Object)],Clazz.prototype,'selected',void0);__decorate([NotInput(),__metadata('design:type',Object)],Clazz.prototype,'notSelected',void0,);ComponentClazz=__decorate([NotComponent(),Component({selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css'],}),],ComponentClazz,);returnComponentClazz;})();// outputimport{Injectable,Input,Component}from'@angular/core';import{NotInjectable,NotComponent}from'another-lib';varClazz=(function(){functionClazz(){}returnClazz;})();Clazz.decorators=[{type: NotInjectable}];varComponentClazz=(function(){functionComponentClazz(){}__decorate([NotInput(),__metadata('design:type',Object)],Clazz.prototype,'notSelected',void0,);ComponentClazz=__decorate([NotComponent()],ComponentClazz);returnComponentClazz;})();Adds /*@__PURE__*/ comments to top level downleveled class declarations and instantiation.
Warning: this transform assumes the file is a pure module. It should not be used with unpure modules.
// inputvarClazz=(function(){functionClazz(){}returnClazz;})();varnewClazz=newClazz();varnewClazzTwo=Clazz();// outputvarClazz=/*@__PURE__*/(function(){functionClazz(){}returnClazz;})();varnewClazz=/*@__PURE__*/newClazz();varnewClazzTwo=/*@__PURE__*/Clazz();Adds /*@__PURE__*/ to downleveled TypeScript classes.
// inputvarReplayEvent=(function(){functionReplayEvent(time,value){this.time=time;this.value=value;}returnReplayEvent;})();// outputvarReplayEvent=/*@__PURE__*/(function(){functionReplayEvent(time,value){this.time=time;this.value=value;}returnReplayEvent;})();TypeScript helpers (__extends/__decorate/__metadata/__param) are replaced with tslib imports whenever found.
// inputvar__extends=(this&&this.__extends)||function(d,b){for(varpinb)if(b.hasOwnProperty(p))d[p]=b[p];function__(){this.constructor=d;}d.prototype=b===null ? Object.create(b) : ((__.prototype=b.prototype),new__());};// outputimport{__extends}from'tslib';Wrap downleveled TypeScript enums in a function, and adds /*@__PURE__*/ comment.
// inputvarChangeDetectionStrategy;(function(ChangeDetectionStrategy){ChangeDetectionStrategy[(ChangeDetectionStrategy['OnPush']=0)]='OnPush';ChangeDetectionStrategy[(ChangeDetectionStrategy['Default']=1)]='Default';})(ChangeDetectionStrategy||(ChangeDetectionStrategy={}));// outputvarChangeDetectionStrategy=/*@__PURE__*/(function(){varChangeDetectionStrategy={};ChangeDetectionStrategy[(ChangeDetectionStrategy['OnPush']=0)]='OnPush';ChangeDetectionStrategy[(ChangeDetectionStrategy['Default']=1)]='Default';returnChangeDetectionStrategy;})();import{buildOptimizer}from'@angular-devkit/build-optimizer';consttranspiledContent=buildOptimizer({content: input}).content;Available options:
exportinterfaceBuildOptimizerOptions{content?: string;inputFilePath?: string;outputFilePath?: string;emitSourceMap?: boolean;strict?: boolean;isSideEffectFree?: boolean;}import{BuildOptimizerWebpackPlugin}from'@angular-devkit/build-optimizer';module.exports={plugins: [newBuildOptimizerWebpackPlugin(),]module: {rules: [{test: /\.js$/,loader: '@angular-devkit/build-optimizer/webpack-loader',options: {sourceMap: false}}]}}build-optimizer input.js build-optimizer input.js output.js