0.1302.1 • Published 2 years ago

@angular-devkit/build-optimizer v0.1302.1

Weekly downloads
1,830,315
License
MIT
Repository
github
Last release
2 years ago

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:

Non-transform optimizations are applied via the Purify Plugin.

Some of these optimizations add /*@__PURE__*/ comments. These are used by UglifyJS 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. Webpack library imports are also marked as /*@__PURE__*/ when used with Purify Plugin.

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;
})();

Purify Plugin

Performs regex based replacements on all bundles that add /*@__PURE__*/ comments to known pure webpack imports (used with Prefix functions).

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 and plugin usage:

const PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;

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

CLI usage

build-optimizer input.js
build-optimizer input.js output.js
purify input.js
purify input.js output.js
0.1202.18

2 years ago

0.1202.17

2 years ago

0.1102.19

2 years ago

0.1202.15

2 years ago

0.1202.14

3 years ago

0.1202.16

2 years ago

0.1301.0-rc.0

3 years ago

0.1302.0-rc.1

2 years ago

0.1302.0-rc.0

2 years ago

0.1301.3

2 years ago

0.1301.4

2 years ago

0.1301.1

3 years ago

0.1301.2

3 years ago

0.1301.0

3 years ago

0.1302.0-next.2

2 years ago

0.1102.16

3 years ago

0.1102.17

3 years ago

0.1102.18

2 years ago

0.1302.0

2 years ago

0.1302.1

2 years ago

0.1302.0-next.0

3 years ago

0.1302.0-next.1

3 years ago

0.1002.4

3 years ago

0.1301.0-next.1

3 years ago

0.1301.0-next.2

3 years ago

0.1301.0-next.3

3 years ago

0.1300.4

3 years ago

0.1300.2

3 years ago

0.1300.3

3 years ago

0.1300.0-rc.3

3 years ago

0.1300.0-rc.2

3 years ago

0.1202.13

3 years ago

0.1202.12

3 years ago

0.1301.0-next.0

3 years ago

0.1300.0

3 years ago

0.1300.1

3 years ago

0.1102.15

3 years ago

0.1300.0-rc.1

3 years ago

0.1300.0-rc.0

3 years ago

0.1202.11

3 years ago

0.1202.10

3 years ago

0.1202.9

3 years ago

0.1300.0-next.9

3 years ago

0.1300.0-next.8

3 years ago

0.1202.8

3 years ago

0.1300.0-next.7

3 years ago

0.1202.7

3 years ago

0.1300.0-next.6

3 years ago

0.1202.6

3 years ago

0.1300.0-next.5

3 years ago

0.1202.5

3 years ago

0.1300.0-next.4

3 years ago

0.1202.4

3 years ago

0.1300.0-next.3

3 years ago

0.1202.3

3 years ago

0.1300.0-next.2

3 years ago

0.1202.2

3 years ago

0.1300.0-next.1

3 years ago

0.1202.1

3 years ago

0.1300.0-next.0

3 years ago

0.1202.0

3 years ago

0.1202.0-rc.0

3 years ago

0.1201.4

3 years ago

0.1201.3

3 years ago

0.1202.0-next.3

3 years ago

0.1201.2

3 years ago

0.1202.0-next.2

3 years ago

0.1201.1

3 years ago

0.1201.0

3 years ago

0.1202.0-next.0

3 years ago

0.1201.0-next.6

3 years ago

0.1200.5

3 years ago

0.1201.0-next.5

3 years ago

0.1200.4

3 years ago

0.1102.14

3 years ago

0.1201.0-next.4

3 years ago

0.1200.3

3 years ago

0.1201.0-next.3

3 years ago

0.1200.2

3 years ago

0.1201.0-next.2

3 years ago

0.1200.0

3 years ago

0.1200.1

3 years ago

0.1102.13

3 years ago

0.1200.0-rc.3

3 years ago

0.1102.11

3 years ago

0.1102.12

3 years ago

0.1200.0-rc.1

3 years ago

0.1200.0-rc.2

3 years ago

0.1102.10

3 years ago

0.1200.0-rc.0

3 years ago

0.1200.0-next.9

3 years ago

0.1102.9

3 years ago

0.1200.0-next.8

3 years ago

0.1102.8

3 years ago

0.1200.0-next.7

3 years ago

0.1102.7

3 years ago

0.1200.0-next.6

3 years ago

0.1102.6

3 years ago

0.1200.0-next.5

3 years ago

0.1102.5

3 years ago

0.1200.0-next.4

3 years ago

0.1102.4

3 years ago

0.1200.0-next.3

3 years ago

0.1102.3

3 years ago

0.901.15

3 years ago

0.1002.3

3 years ago

0.1200.0-next.2

3 years ago

0.1102.2

3 years ago

0.1200.0-next.1

3 years ago

0.1102.1

3 years ago

0.1200.0-next.0

3 years ago

0.1102.0

3 years ago

0.901.14

3 years ago

0.1002.2

3 years ago

0.1101.3

3 years ago

0.1101.4

3 years ago

0.1102.0-rc.1

3 years ago

0.1102.0-rc.0

3 years ago

0.1101.2

3 years ago

0.1102.0-next.0

3 years ago

0.1101.1

3 years ago

0.1101.0

3 years ago

0.1101.0-rc.0

3 years ago

0.1100.7

3 years ago

0.1100.6

4 years ago

0.1101.0-next.4

4 years ago

0.1002.1

4 years ago

0.901.13

4 years ago

0.1100.5

4 years ago

0.1101.0-next.3

4 years ago

0.1101.0-next.2

4 years ago

0.1100.4

4 years ago

0.1100.3

4 years ago

0.1101.0-next.1

4 years ago

0.1100.2

4 years ago

0.1101.0-next.0

4 years ago

0.1100.1

4 years ago

0.1100.0

4 years ago

0.1100.0-rc.3

4 years ago

0.1100.0-rc.2

4 years ago

0.1100.0-rc.1

4 years ago

0.1100.0-rc.0

4 years ago

0.1002.0

4 years ago

0.1001.7

4 years ago

0.1100.0-next.7

4 years ago

0.1100.0-next.6

4 years ago

0.1100.0-next.5

4 years ago

0.1001.6

4 years ago

0.1001.5

4 years ago

0.1100.0-next.4

4 years ago

0.1001.4

4 years ago

0.1100.0-next.3

4 years ago

0.1001.3

4 years ago

0.1001.2

4 years ago

0.1100.0-next.2

4 years ago

0.1001.1

4 years ago

0.1100.0-next.1

4 years ago

0.1100.0-next.0

4 years ago

0.1001.0

4 years ago

0.1001.0-rc.0

4 years ago

0.1000.8

4 years ago

0.1001.0-next.7

4 years ago

0.1000.7

4 years ago

0.1001.0-next.6

4 years ago

0.1001.0-next.5

4 years ago

0.1000.6

4 years ago

0.1001.0-next.4

4 years ago

0.1001.0-next.3

4 years ago

0.1000.5

4 years ago

0.803.29

4 years ago

0.901.12

4 years ago

0.1001.0-next.2

4 years ago

0.1000.4

4 years ago

0.1000.3

4 years ago

0.1001.0-next.1

4 years ago

0.901.11

4 years ago

0.1000.2

4 years ago

0.1001.0-next.0

4 years ago

0.901.10

4 years ago

0.1000.1

4 years ago

0.1000.0

4 years ago

0.803.28

4 years ago

0.901.9

4 years ago

0.1000.0-rc.5

4 years ago

0.1000.0-rc.4

4 years ago

0.1000.0-rc.3

4 years ago

0.803.27

4 years ago

0.901.8

4 years ago

0.1000.0-rc.2

4 years ago

0.1000.0-rc.0

4 years ago

0.901.7

4 years ago

0.1000.0-next.6

4 years ago

0.1000.0-next.5

4 years ago

0.901.6

4 years ago

0.901.5

4 years ago

0.1000.0-next.4

4 years ago

0.1000.0-next.3

4 years ago

0.901.4

4 years ago

0.1000.0-next.2

4 years ago

0.901.3

4 years ago

0.1000.0-next.1

4 years ago

0.901.2

4 years ago

0.1000.0-next.0

4 years ago

0.901.1

4 years ago

0.803.26

4 years ago

0.13.10

4 years ago

0.901.0

4 years ago

0.901.0-rc.0

4 years ago

0.901.0-next.4

4 years ago

0.900.7

4 years ago

0.901.0-next.3

4 years ago

0.900.6

4 years ago

0.901.0-next.2

4 years ago

0.900.5

4 years ago

0.901.0-next.1

4 years ago

0.900.4

4 years ago

0.901.0-next.0

4 years ago

0.900.3

4 years ago

0.900.2

4 years ago

0.900.1

4 years ago

0.900.0

4 years ago

0.803.25

4 years ago

0.900.0-rc.14

4 years ago

0.900.0-rc.13

4 years ago

0.803.24

4 years ago

0.900.0-rc.12

4 years ago

0.900.0-rc.11

4 years ago

0.900.0-rc.10

4 years ago

0.803.23

4 years ago

0.900.0-rc.9

4 years ago

0.803.22

5 years ago

0.900.0-rc.8

5 years ago

0.900.0-rc.7

5 years ago

0.803.21

5 years ago

0.900.0-rc.6

5 years ago

0.900.0-rc.5

5 years ago

0.803.20

5 years ago

0.900.0-rc.4

5 years ago

0.900.0-rc.3

5 years ago

0.900.0-rc.2

5 years ago

0.803.19

5 years ago

0.803.18

5 years ago

0.900.0-rc.1

5 years ago

0.900.0-rc.0

5 years ago

0.803.17

5 years ago

0.900.0-next.19

5 years ago

0.803.16

5 years ago

0.900.0-next.18

5 years ago

0.900.0-next.17

5 years ago

0.803.15

5 years ago

0.900.0-next.16

5 years ago

0.900.0-next.15

5 years ago

0.803.14

5 years ago

0.900.0-next.14

5 years ago

0.803.13

5 years ago

0.900.0-next.13

5 years ago

0.803.12

5 years ago

0.900.0-next.12

5 years ago

0.900.0-next.11

5 years ago

0.803.10

5 years ago

0.900.0-next.10

5 years ago

0.803.9

5 years ago

0.900.0-next.9

5 years ago

0.900.0-next.8

5 years ago

0.803.8

5 years ago

0.900.0-next.7

5 years ago

0.803.7

5 years ago

0.900.0-next.6

5 years ago

0.803.6

5 years ago

0.803.5

5 years ago

0.900.0-next.5

5 years ago

0.803.4

5 years ago

0.900.0-next.4

5 years ago

0.900.0-next.3

5 years ago

0.803.3

5 years ago

0.900.0-next.2

5 years ago

0.803.2

5 years ago

0.803.1

5 years ago

0.900.0-next.1

5 years ago

0.900.0-next.0

5 years ago

0.803.0

5 years ago

0.803.0-rc.0

5 years ago

0.802.2

5 years ago

0.803.0-next.2

5 years ago

0.803.0-next.1

5 years ago

0.802.1

5 years ago

0.802.0

5 years ago

0.803.0-next.0

5 years ago

0.801.3

5 years ago

0.802.0-rc.0

5 years ago

0.802.0-next.1

5 years ago

0.801.2

5 years ago

0.802.0-next.0

5 years ago

0.801.1

5 years ago

0.801.0

5 years ago

0.800.6

5 years ago

0.800.5

5 years ago

0.801.0-rc.0

5 years ago

0.801.0-beta.3

5 years ago

0.800.4

5 years ago

0.801.0-beta.2

5 years ago

0.801.0-beta.1

5 years ago

0.801.0-beta.0

5 years ago

0.800.3

5 years ago

0.800.2

5 years ago

0.800.1

5 years ago

0.800.0

5 years ago

0.800.0-rc.4

5 years ago

0.800.0-rc.3

5 years ago

0.13.9

5 years ago

0.800.0-rc.2

5 years ago

0.800.0-rc.1

5 years ago

0.800.0-rc.0

5 years ago

0.800.0-beta.18

5 years ago

0.800.0-beta.17

5 years ago

0.800.0-beta.16

5 years ago

0.800.0-beta.15

5 years ago

0.800.0-beta.14

5 years ago

0.800.0-beta.13

5 years ago

0.800.0-beta.12

5 years ago

0.800.0-beta.11

5 years ago

0.13.8

5 years ago

0.800.0-beta.10

5 years ago

0.13.7

5 years ago

0.800.0-beta.9

5 years ago

0.800.0-beta.8

5 years ago

0.800.0-beta.7

5 years ago

0.13.6

5 years ago

0.800.0-beta.6

5 years ago

0.13.5

5 years ago

0.14.0-beta.5

5 years ago

0.13.4

5 years ago

0.14.0-beta.4

5 years ago

0.14.0-beta.2

5 years ago

0.13.3

5 years ago

0.14.0-beta.1

5 years ago

0.13.2

5 years ago

0.13.1

5 years ago

0.14.0-beta.0

5 years ago

0.13.0

5 years ago

0.12.4

5 years ago

0.13.0-rc.0

5 years ago

0.12.3

5 years ago

0.12.2

5 years ago

0.13.0-beta.0

5 years ago

0.12.1

6 years ago

0.12.0

6 years ago

0.8.9

6 years ago

0.12.0-rc.0

6 years ago

0.11.4

6 years ago

0.12.0-beta.2

6 years ago

0.11.3

6 years ago

0.12.0-beta.1

6 years ago

0.11.2

6 years ago

0.11.1

6 years ago

0.12.0-beta.0

6 years ago

0.8.8

6 years ago

0.11.0

6 years ago

0.10.7

6 years ago

0.11.0-rc.0

6 years ago

0.10.6

6 years ago

0.10.5

6 years ago

0.11.0-beta.1

6 years ago

0.8.7

6 years ago

0.11.0-beta.0

6 years ago

0.10.4

6 years ago

0.10.3

6 years ago

0.8.6

6 years ago

0.10.2

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.8.5

6 years ago

0.9.0-rc.3

6 years ago

0.9.0-rc.2

6 years ago

0.9.0-rc.1

6 years ago

0.8.4

6 years ago

0.6.0-rc.0

6 years ago

0.9.0-rc.0

6 years ago

0.9.0-beta.4

6 years ago

0.8.3

6 years ago

0.9.0-beta.3

6 years ago

0.8.2

6 years ago

0.9.0-beta.2

6 years ago

0.9.0-beta.1

6 years ago

0.9.0-beta.0

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.8.0-rc.1

6 years ago

0.8.0-rc.0

6 years ago

0.7.5

6 years ago

0.7.4

6 years ago

0.8.0-beta.3

6 years ago

0.8.0-beta.2

6 years ago

0.7.3

6 years ago

0.8.0-beta.1

6 years ago

0.8.0-beta.0

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.7.0-rc.3

6 years ago

0.7.0-rc.2

6 years ago

0.7.0-rc.1

6 years ago

0.7.0-rc.0

6 years ago

0.7.0-beta.2

6 years ago

0.6.8

6 years ago

0.7.0-beta.1

6 years ago

0.7.0-beta.0

6 years ago

0.6.7

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.13

6 years ago

0.5.12

6 years ago

0.5.11

6 years ago

0.5.10

6 years ago

0.5.9

6 years ago

0.5.8

6 years ago

0.5.7

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.9

6 years ago

0.4.8

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.3.2

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.0.42

6 years ago

0.0.41

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago

0.0.38

7 years ago

0.0.37

7 years ago

0.0.36

7 years ago

0.0.35

7 years ago

0.0.34

7 years ago

0.0.33

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago