@angular-devkit/build-optimizer
Angular Build Optimizer
Last updated 10 days ago by angular .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @angular-devkit/build-optimizer 
SYNC missed versions from official npm registry.

Angular Build Optimizer

Angular Build Optimizer contains Angular optimizations applicable to JavaScript code as a TypeScript transform pipeline.

Available optimizations

Transformations applied depend on file content:

Some of these optimizations add /*@__PURE__*/ comments. These are used by JS optimization tools to identify pure functions that can potentially be dropped.

Class fold

Static properties are folded into ES5 classes:

// input
var Clazz = (function () { function Clazz() { } return Clazz; }());
Clazz.prop = 1;

// output
var Clazz = (function () { function Clazz() { } Clazz.prop = 1; return Clazz; }());

Scrub file

Angular decorators, property decorators and constructor parameters are removed, while leaving non-Angular ones intact.

// input
import { Injectable, Input, Component } from '@angular/core';
import { NotInjectable, NotComponent, NotInput } from 'another-lib';
var Clazz = (function () { function Clazz() { } return Clazz; }());
Clazz.decorators = [{ type: Injectable }, { type: NotInjectable }];
Clazz.propDecorators = { 'ngIf': [{ type: Input }] };
Clazz.ctorParameters = function () { return [{type: Injector}]; };
var ComponentClazz = (function () {
  function ComponentClazz() { }
  __decorate([
    Input(),
    __metadata("design:type", Object)
  ], Clazz.prototype, "selected", void 0);
  __decorate([
    NotInput(),
    __metadata("design:type", Object)
  ], Clazz.prototype, "notSelected", void 0);
  ComponentClazz = __decorate([
    NotComponent(),
    Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
    })
  ], ComponentClazz);
  return ComponentClazz;
}());

// output
import { Injectable, Input, Component } from '@angular/core';
import { NotInjectable, NotComponent } from 'another-lib';
var Clazz = (function () { function Clazz() { } return Clazz; }());
Clazz.decorators = [{ type: NotInjectable }];
var ComponentClazz = (function () {
  function ComponentClazz() { }
  __decorate([
    NotInput(),
    __metadata("design:type", Object)
  ], Clazz.prototype, "notSelected", void 0);
  ComponentClazz = __decorate([
    NotComponent()
  ], ComponentClazz);
  return ComponentClazz;
}());

Prefix functions

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.

// input
var Clazz = (function () { function Clazz() { } return Clazz; }());
var newClazz = new Clazz();
var newClazzTwo = Clazz();

// output
var Clazz = /*@__PURE__*/ (function () { function Clazz() { } return Clazz; }());
var newClazz = /*@__PURE__*/ new Clazz();
var newClazzTwo = /*@__PURE__*/ Clazz();

Prefix Classes

Adds /*@__PURE__*/ to downleveled TypeScript classes.

// input
var ReplayEvent = (function () {
    function ReplayEvent(time, value) {
        this.time = time;
        this.value = value;
    }
    return ReplayEvent;
}());

// output
var ReplayEvent = /*@__PURE__*/ (function () {
    function ReplayEvent(time, value) {
        this.time = time;
        this.value = value;
    }
    return ReplayEvent;
}());

Import tslib

TypeScript helpers (__extends/__decorate/__metadata/__param) are replaced with tslib imports whenever found.

// input
var __extends = (this && this.__extends) || function (d, b) {
  for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  function __() { this.constructor = d; }
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};

// output
import { __extends } from "tslib";

Wrap enums

Wrap downleveled TypeScript enums in a function, and adds /*@__PURE__*/ comment.

// input
var ChangeDetectionStrategy;
(function (ChangeDetectionStrategy) {
    ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
    ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default";
})(ChangeDetectionStrategy || (ChangeDetectionStrategy = {}));

// output
var ChangeDetectionStrategy = /*@__PURE__*/ (function () {
  var ChangeDetectionStrategy = {};
  ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
  ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default";
  return ChangeDetectionStrategy;
})();

Library Usage

import { buildOptimizer } from '@angular-devkit/build-optimizer';

const transpiledContent = buildOptimizer({ content: input }).content;

Available options:

export interface BuildOptimizerOptions {
  content?: string;
  inputFilePath?: string;
  outputFilePath?: string;
  emitSourceMap?: boolean;
  strict?: boolean;
  isSideEffectFree?: boolean;
}

Webpack loader usage:

import { BuildOptimizerWebpackPlugin } from '@angular-devkit/build-optimizer';

module.exports = {
  plugins: [
    new BuildOptimizerWebpackPlugin(),
  ]
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: '@angular-devkit/build-optimizer/webpack-loader',
        options: {
          sourceMap: false
        }
      }
    ]
  }
}

CLI usage

build-optimizer input.js
build-optimizer input.js output.js

Current Tags

  • 0.803.20                                ...           latest (10 days ago)
  • 0.900.0-rc.5                                ...           next (3 days ago)
  • 0.8.9                                ...           v6-lts (a year ago)

246 Versions

  • 0.900.0-rc.5                                ...           3 days ago
  • 0.803.20                                ...           10 days ago
  • 0.900.0-rc.4                                ...           10 days ago
  • 0.900.0-rc.3                                ...           17 days ago
  • 0.900.0-rc.2                                ...           24 days ago
  • 0.803.19                                ...           24 days ago
  • 0.803.18                                ...           a month ago
  • 0.900.0-rc.1                                ...           a month ago
  • 0.900.0-rc.0                                ...           a month ago
  • 0.803.17                                ...           a month ago
  • 0.900.0-next.19                                ...           a month ago
  • 0.803.16                                ...           a month ago
  • 0.900.0-next.18                                ...           a month ago
  • 0.900.0-next.17                                ...           a month ago
  • 0.803.15                                ...           a month ago
  • 0.900.0-next.16                                ...           a month ago
  • 0.900.0-next.15                                ...           a month ago
  • 0.803.14                                ...           a month ago
  • 0.900.0-next.14                                ...           a month ago
  • 0.803.13                                ...           a month ago
  • 0.900.0-next.13                                ...           2 months ago
  • 0.803.12                                ...           2 months ago
  • 0.900.0-next.12                                ...           2 months ago
  • 0.900.0-next.11                                ...           2 months ago
  • 0.803.10                                ...           2 months ago
  • 0.900.0-next.10                                ...           2 months ago
  • 0.803.9                                ...           2 months ago
  • 0.900.0-next.9                                ...           2 months ago
  • 0.900.0-next.8                                ...           2 months ago
  • 0.803.8                                ...           2 months ago
  • 0.900.0-next.7                                ...           2 months ago
  • 0.803.7                                ...           2 months ago
  • 0.900.0-next.6                                ...           2 months ago
  • 0.803.6                                ...           2 months ago
  • 0.803.5                                ...           3 months ago
  • 0.900.0-next.5                                ...           3 months ago
  • 0.803.4                                ...           3 months ago
  • 0.900.0-next.4                                ...           3 months ago
  • 0.900.0-next.3                                ...           3 months ago
  • 0.803.3                                ...           3 months ago
  • 0.900.0-next.2                                ...           3 months ago
  • 0.803.2                                ...           3 months ago
  • 0.803.1                                ...           3 months ago
  • 0.900.0-next.1                                ...           3 months ago
  • 0.900.0-next.0                                ...           3 months ago
  • 0.803.0                                ...           3 months ago
  • 0.803.0-rc.0                                ...           4 months ago
  • 0.802.2                                ...           4 months ago
  • 0.803.0-next.2                                ...           4 months ago
  • 0.803.0-next.1                                ...           4 months ago
  • 0.802.1                                ...           4 months ago
  • 0.802.0                                ...           4 months ago
  • 0.803.0-next.0                                ...           4 months ago
  • 0.801.3                                ...           4 months ago
  • 0.802.0-rc.0                                ...           4 months ago
  • 0.802.0-next.1                                ...           5 months ago
  • 0.801.2                                ...           5 months ago
  • 0.802.0-next.0                                ...           5 months ago
  • 0.801.1                                ...           5 months ago
  • 0.801.0                                ...           5 months ago
  • 0.800.6                                ...           5 months ago
  • 0.800.5                                ...           5 months ago
  • 0.801.0-rc.0                                ...           5 months ago
  • 0.801.0-beta.3                                ...           5 months ago
  • 0.800.4                                ...           5 months ago
  • 0.801.0-beta.2                                ...           6 months ago
  • 0.801.0-beta.1                                ...           6 months ago
  • 0.801.0-beta.0                                ...           6 months ago
  • 0.800.3                                ...           6 months ago
  • 0.800.2                                ...           6 months ago
  • 0.800.1                                ...           6 months ago
  • 0.800.0                                ...           6 months ago
  • 0.800.0-rc.4                                ...           7 months ago
  • 0.800.0-rc.3                                ...           7 months ago
  • 0.13.9                                ...           7 months ago
  • 0.800.0-rc.2                                ...           7 months ago
  • 0.800.0-rc.1                                ...           7 months ago
  • 0.800.0-rc.0                                ...           7 months ago
  • 0.800.0-beta.18                                ...           7 months ago
  • 0.800.0-beta.17                                ...           7 months ago
  • 0.800.0-beta.16                                ...           8 months ago
  • 0.800.0-beta.15                                ...           8 months ago
  • 0.800.0-beta.14                                ...           8 months ago
  • 0.800.0-beta.13                                ...           8 months ago
  • 0.800.0-beta.12                                ...           8 months ago
  • 0.800.0-beta.11                                ...           8 months ago
  • 0.13.8                                ...           8 months ago
  • 0.800.0-beta.10                                ...           8 months ago
  • 0.13.7                                ...           8 months ago
  • 0.800.0-beta.9                                ...           8 months ago
  • 0.800.0-beta.8                                ...           9 months ago
  • 0.800.0-beta.7                                ...           9 months ago
  • 0.13.6                                ...           9 months ago
  • 0.800.0-beta.6                                ...           9 months ago
  • 0.13.5                                ...           9 months ago
  • 0.14.0-beta.5                                ...           9 months ago
  • 0.13.4                                ...           9 months ago
  • 0.14.0-beta.4                                ...           9 months ago
  • 0.14.0-beta.2                                ...           10 months ago
  • 0.13.3                                ...           10 months ago
  • 0.14.0-beta.1                                ...           10 months ago
  • 0.13.2                                ...           10 months ago
  • 0.13.1                                ...           10 months ago
  • 0.14.0-beta.0                                ...           10 months ago
  • 0.13.0                                ...           10 months ago
  • 0.12.4                                ...           10 months ago
  • 0.13.0-rc.0                                ...           10 months ago
  • 0.12.3                                ...           10 months ago
  • 0.12.2                                ...           a year ago
  • 0.13.0-beta.0                                ...           a year ago
  • 0.12.1                                ...           a year ago
  • 0.12.0                                ...           a year ago
  • 0.8.9                                ...           a year ago
  • 0.12.0-rc.0                                ...           a year ago
  • 0.11.4                                ...           a year ago
  • 0.12.0-beta.2                                ...           a year ago
  • 0.11.3                                ...           a year ago
  • 0.12.0-beta.1                                ...           a year ago
  • 0.11.2                                ...           a year ago
  • 0.11.1                                ...           a year ago
  • 0.12.0-beta.0                                ...           a year ago
  • 0.8.8                                ...           a year ago
  • 0.11.0                                ...           a year ago
  • 0.10.7                                ...           a year ago
  • 0.11.0-rc.0                                ...           a year ago
  • 0.10.6                                ...           a year ago
  • 0.10.5                                ...           a year ago
  • 0.11.0-beta.1                                ...           a year ago
  • 0.8.7                                ...           a year ago
  • 0.11.0-beta.0                                ...           a year ago
  • 0.10.4                                ...           a year ago
  • 0.10.3                                ...           a year ago
  • 0.8.6                                ...           a year ago
  • 0.10.2                                ...           a year ago
  • 0.10.1                                ...           a year ago
  • 0.8.5                                ...           a year ago
  • 0.9.0-rc.3                                ...           a year ago
  • 0.9.0-rc.2                                ...           a year ago
  • 0.9.0-rc.1                                ...           a year ago
  • 0.8.4                                ...           a year ago
  • 0.9.0-rc.0                                ...           a year ago
  • 0.9.0-beta.4                                ...           a year ago
  • 0.8.3                                ...           a year ago
  • 0.9.0-beta.3                                ...           a year ago
  • 0.8.2                                ...           a year ago
  • 0.9.0-beta.2                                ...           a year ago
  • 0.9.0-beta.1                                ...           a year ago
  • 0.9.0-beta.0                                ...           a year ago
  • 0.8.1                                ...           a year ago
  • 0.8.0                                ...           a year ago
  • 0.8.0-rc.1                                ...           a year ago
  • 0.8.0-rc.0                                ...           a year ago
  • 0.7.5                                ...           a year ago
  • 0.7.4                                ...           a year ago
  • 0.8.0-beta.3                                ...           a year ago
  • 0.8.0-beta.2                                ...           a year ago
  • 0.7.3                                ...           a year ago
  • 0.8.0-beta.1                                ...           a year ago
  • 0.8.0-beta.0                                ...           a year ago
  • 0.7.2                                ...           a year ago
  • 0.7.1                                ...           a year ago
  • 0.7.0                                ...           a year ago
  • 0.7.0-rc.3                                ...           a year ago
  • 0.7.0-rc.2                                ...           a year ago
  • 0.7.0-rc.1                                ...           a year ago
  • 0.7.0-rc.0                                ...           a year ago
  • 0.7.0-beta.2                                ...           2 years ago
  • 0.6.8                                ...           2 years ago
  • 0.7.0-beta.1                                ...           2 years ago
  • 0.7.0-beta.0                                ...           2 years ago
  • 0.6.7                                ...           2 years ago
  • 0.6.6                                ...           2 years ago
  • 0.6.5                                ...           2 years ago
  • 0.6.4                                ...           2 years ago
  • 0.6.3                                ...           2 years ago
  • 0.6.2                                ...           2 years ago
  • 0.6.1                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.13                                ...           2 years ago
  • 0.5.12                                ...           2 years ago
  • 0.5.11                                ...           2 years ago
  • 0.5.10                                ...           2 years ago
  • 0.5.9                                ...           2 years ago
  • 0.5.8                                ...           2 years ago
  • 0.5.7                                ...           2 years ago
  • 0.5.6                                ...           2 years ago
  • 0.5.5                                ...           2 years ago
  • 0.5.4                                ...           2 years ago
  • 0.5.3                                ...           2 years ago
  • 0.5.2                                ...           2 years ago
  • 0.5.1                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.9                                ...           2 years ago
  • 0.4.8                                ...           2 years ago
  • 0.4.7                                ...           2 years ago
  • 0.4.6                                ...           2 years ago
  • 0.4.5                                ...           2 years ago
  • 0.4.4                                ...           2 years ago
  • 0.4.3                                ...           2 years ago
  • 0.4.2                                ...           2 years ago
  • 0.4.1                                ...           2 years ago
  • 0.3.2                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.0.42                                ...           2 years ago
  • 0.0.41                                ...           2 years ago
  • 0.0.40                                ...           2 years ago
  • 0.0.39                                ...           2 years ago
  • 0.0.38                                ...           2 years ago
  • 0.0.37                                ...           2 years ago
  • 0.0.36                                ...           2 years ago
  • 0.0.35                                ...           2 years ago
  • 0.0.34                                ...           2 years ago
  • 0.0.33                                ...           2 years ago
  • 0.0.32                                ...           2 years ago
  • 0.0.31                                ...           2 years ago
  • 0.0.30                                ...           2 years ago
  • 0.0.29                                ...           2 years ago
  • 0.0.28                                ...           2 years ago
  • 0.0.27                                ...           2 years ago
  • 0.0.26                                ...           2 years ago
  • 0.0.25                                ...           2 years ago
  • 0.0.24                                ...           2 years ago
  • 0.0.23                                ...           2 years ago
  • 0.0.22                                ...           2 years ago
  • 0.0.21                                ...           2 years ago
  • 0.0.20                                ...           2 years ago
  • 0.0.19                                ...           2 years ago
  • 0.0.18                                ...           2 years ago
  • 0.0.16                                ...           2 years ago
  • 0.0.15                                ...           2 years ago
  • 0.0.14                                ...           2 years ago
  • 0.0.13                                ...           2 years ago
  • 0.0.12                                ...           2 years ago
  • 0.0.11                                ...           2 years ago
  • 0.0.10                                ...           2 years ago
  • 0.0.9                                ...           2 years ago
  • 0.0.8                                ...           2 years ago
  • 0.0.7                                ...           2 years ago
  • 0.0.6                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago

Copyright 2014 - 2017 © taobao.org |