0.1302.1 • Published 2 months ago

@angular-devkit/build-optimizer v0.1302.1

Weekly downloads
1,830,315
License
MIT
Repository
github
Last release
2 months 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 months ago

0.1202.17

6 months ago

0.1102.19

6 months ago

0.1202.15

9 months ago

0.1202.14

10 months ago

0.1202.16

8 months ago

0.1301.0-rc.0

10 months ago

0.1302.0-rc.1

8 months ago

0.1302.0-rc.0

8 months ago

0.1301.3

9 months ago

0.1301.4

8 months ago

0.1301.1

10 months ago

0.1301.2

9 months ago

0.1301.0

10 months ago

0.1302.0-next.2

9 months ago

0.1102.16

9 months ago

0.1102.17

9 months ago

0.1102.18

8 months ago

0.1302.0

8 months ago

0.1302.1

8 months ago

0.1302.0-next.0

10 months ago

0.1302.0-next.1

9 months ago

0.1002.4

9 months ago

0.1301.0-next.1

11 months ago

0.1301.0-next.2

10 months ago

0.1301.0-next.3

10 months ago

0.1300.4

10 months ago

0.1300.2

11 months ago

0.1300.3

10 months ago

0.1300.0-rc.3

11 months ago

0.1300.0-rc.2

11 months ago

0.1202.13

11 months ago

0.1202.12

11 months ago

0.1301.0-next.0

11 months ago

0.1300.0

11 months ago

0.1300.1

11 months ago

0.1102.15

11 months ago

0.1300.0-rc.1

11 months ago

0.1300.0-rc.0

12 months ago

0.1202.11

11 months ago

0.1202.10

12 months ago

0.1202.9

12 months ago

0.1300.0-next.9

12 months ago

0.1300.0-next.8

12 months ago

0.1202.8

12 months ago

0.1300.0-next.7

12 months ago

0.1202.7

1 year ago

0.1300.0-next.6

1 year ago

0.1202.6

1 year ago

0.1300.0-next.5

1 year ago

0.1202.5

1 year ago

0.1300.0-next.4

1 year ago

0.1202.4

1 year ago

0.1300.0-next.3

1 year ago

0.1202.3

1 year ago

0.1300.0-next.2

1 year ago

0.1202.2

1 year ago

0.1300.0-next.1

1 year ago

0.1202.1

1 year ago

0.1300.0-next.0

1 year ago

0.1202.0

1 year ago

0.1202.0-rc.0

1 year ago

0.1201.4

1 year ago

0.1201.3

1 year ago

0.1202.0-next.3

1 year ago

0.1201.2

1 year ago

0.1202.0-next.2

1 year ago

0.1201.1

1 year ago

0.1201.0

1 year ago

0.1202.0-next.0

1 year ago

0.1201.0-next.6

1 year ago

0.1200.5

1 year ago

0.1201.0-next.5

1 year ago

0.1200.4

1 year ago

0.1102.14

1 year ago

0.1201.0-next.4

1 year ago

0.1200.3

1 year ago

0.1201.0-next.3

1 year ago

0.1200.2

1 year ago

0.1201.0-next.2

1 year ago

0.1200.0

1 year ago

0.1200.1

1 year ago

0.1102.13

1 year ago

0.1200.0-rc.3

1 year ago

0.1102.11

1 year ago

0.1102.12

1 year ago

0.1200.0-rc.1

1 year ago

0.1200.0-rc.2

1 year ago

0.1102.10

1 year ago

0.1200.0-rc.0

1 year ago

0.1200.0-next.9

1 year ago

0.1102.9

1 year ago

0.1200.0-next.8

1 year ago

0.1102.8

1 year ago

0.1200.0-next.7

1 year ago

0.1102.7

1 year ago

0.1200.0-next.6

2 years ago

0.1102.6

2 years ago

0.1200.0-next.5

2 years ago

0.1102.5

2 years ago

0.1200.0-next.4

2 years ago

0.1102.4

2 years ago

0.1200.0-next.3

2 years ago

0.1102.3

2 years ago

0.901.15

2 years ago

0.1002.3

2 years ago

0.1200.0-next.2

2 years ago

0.1102.2

2 years ago

0.1200.0-next.1

2 years ago

0.1102.1

2 years ago

0.1200.0-next.0

2 years ago

0.1102.0

2 years ago

0.901.14

2 years ago

0.1002.2

2 years ago

0.1101.3

2 years ago

0.1101.4

2 years ago

0.1102.0-rc.1

2 years ago

0.1102.0-rc.0

2 years ago

0.1101.2

2 years ago

0.1102.0-next.0

2 years ago

0.1101.1

2 years ago

0.1101.0

2 years ago

0.1101.0-rc.0

2 years ago

0.1100.7

2 years ago

0.1100.6

2 years ago

0.1101.0-next.4

2 years ago

0.1002.1

2 years ago

0.901.13

2 years ago

0.1100.5

2 years ago

0.1101.0-next.3

2 years ago

0.1101.0-next.2

2 years ago

0.1100.4

2 years ago

0.1100.3

2 years ago

0.1101.0-next.1

2 years ago

0.1100.2

2 years ago

0.1101.0-next.0

2 years ago

0.1100.1

2 years ago

0.1100.0

2 years ago

0.1100.0-rc.3

2 years ago

0.1100.0-rc.2

2 years ago

0.1100.0-rc.1

2 years ago

0.1100.0-rc.0

2 years ago

0.1002.0

2 years ago

0.1001.7

2 years ago

0.1100.0-next.7

2 years ago

0.1100.0-next.6

2 years ago

0.1100.0-next.5

2 years ago

0.1001.6

2 years ago

0.1001.5

2 years ago

0.1100.0-next.4

2 years ago

0.1001.4

2 years ago

0.1100.0-next.3

2 years ago

0.1001.3

2 years ago

0.1001.2

2 years ago

0.1100.0-next.2

2 years ago

0.1001.1

2 years ago

0.1100.0-next.1

2 years ago

0.1100.0-next.0

2 years ago

0.1001.0

2 years ago

0.1001.0-rc.0

2 years ago

0.1000.8

2 years ago

0.1001.0-next.7

2 years ago

0.1000.7

2 years ago

0.1001.0-next.6

2 years ago

0.1001.0-next.5

2 years ago

0.1000.6

2 years ago

0.1001.0-next.4

2 years ago

0.1001.0-next.3

2 years ago

0.1000.5

2 years ago

0.803.29

2 years ago

0.901.12

2 years ago

0.1001.0-next.2

2 years ago

0.1000.4

2 years ago

0.1000.3

2 years ago

0.1001.0-next.1

2 years ago

0.901.11

2 years ago

0.1000.2

2 years ago

0.1001.0-next.0

2 years ago

0.901.10

2 years ago

0.1000.1

2 years ago

0.1000.0

2 years ago

0.803.28

2 years ago

0.901.9

2 years ago

0.1000.0-rc.5

2 years ago

0.1000.0-rc.4

2 years ago

0.1000.0-rc.3

2 years ago

0.803.27

2 years ago

0.901.8

2 years ago

0.1000.0-rc.2

2 years ago

0.1000.0-rc.0

2 years ago

0.901.7

2 years ago

0.1000.0-next.6

2 years ago

0.1000.0-next.5

2 years ago

0.901.6

2 years ago

0.901.5

2 years ago

0.1000.0-next.4

2 years ago

0.1000.0-next.3

2 years ago

0.901.4

2 years ago

0.1000.0-next.2

2 years ago

0.901.3

2 years ago

0.1000.0-next.1

2 years ago

0.901.2

2 years ago

0.1000.0-next.0

2 years ago

0.901.1

2 years ago

0.803.26

2 years ago

0.13.10

2 years ago

0.901.0

3 years ago

0.901.0-rc.0

3 years ago

0.901.0-next.4

3 years ago

0.900.7

3 years ago

0.901.0-next.3

3 years ago

0.900.6

3 years ago

0.901.0-next.2

3 years ago

0.900.5

3 years ago

0.901.0-next.1

3 years ago

0.900.4

3 years ago

0.901.0-next.0

3 years ago

0.900.3

3 years ago

0.900.2

3 years ago

0.900.1

3 years ago

0.900.0

3 years ago

0.803.25

3 years ago

0.900.0-rc.14

3 years ago

0.900.0-rc.13

3 years ago

0.803.24

3 years ago

0.900.0-rc.12

3 years ago

0.900.0-rc.11

3 years ago

0.900.0-rc.10

3 years ago

0.803.23

3 years ago

0.900.0-rc.9

3 years ago

0.803.22

3 years ago

0.900.0-rc.8

3 years ago

0.900.0-rc.7

3 years ago

0.803.21

3 years ago

0.900.0-rc.6

3 years ago

0.900.0-rc.5

3 years ago

0.803.20

3 years ago

0.900.0-rc.4

3 years ago

0.900.0-rc.3

3 years ago

0.900.0-rc.2

3 years ago

0.803.19

3 years ago

0.803.18

3 years ago

0.900.0-rc.1

3 years ago

0.900.0-rc.0

3 years ago

0.803.17

3 years ago

0.900.0-next.19

3 years ago

0.803.16

3 years ago

0.900.0-next.18

3 years ago

0.900.0-next.17

3 years ago

0.803.15

3 years ago

0.900.0-next.16

3 years ago

0.900.0-next.15

3 years ago

0.803.14

3 years ago

0.900.0-next.14

3 years ago

0.803.13

3 years ago

0.900.0-next.13

3 years ago

0.803.12

3 years ago

0.900.0-next.12

3 years ago

0.900.0-next.11

3 years ago

0.803.10

3 years ago

0.900.0-next.10

3 years ago

0.803.9

3 years ago

0.900.0-next.9

3 years ago

0.900.0-next.8

3 years ago

0.803.8

3 years ago

0.900.0-next.7

3 years ago

0.803.7

3 years ago

0.900.0-next.6

3 years ago

0.803.6

3 years ago

0.803.5

3 years ago

0.900.0-next.5

3 years ago

0.803.4

3 years ago

0.900.0-next.4

3 years ago

0.900.0-next.3

3 years ago

0.803.3

3 years ago

0.900.0-next.2

3 years ago

0.803.2

3 years ago

0.803.1

3 years ago

0.900.0-next.1

3 years ago

0.900.0-next.0

3 years ago

0.803.0

3 years ago

0.803.0-rc.0

3 years ago

0.802.2

3 years ago

0.803.0-next.2

3 years ago

0.803.0-next.1

3 years ago

0.802.1

3 years ago

0.802.0

3 years ago

0.803.0-next.0

3 years ago

0.801.3

3 years ago

0.802.0-rc.0

3 years ago

0.802.0-next.1

3 years ago

0.801.2

3 years ago

0.802.0-next.0

3 years ago

0.801.1

3 years ago

0.801.0

3 years ago

0.800.6

3 years ago

0.800.5

3 years ago

0.801.0-rc.0

3 years ago

0.801.0-beta.3

3 years ago

0.800.4

3 years ago

0.801.0-beta.2

3 years ago

0.801.0-beta.1

3 years ago

0.801.0-beta.0

3 years ago

0.800.3

3 years ago

0.800.2

3 years ago

0.800.1

3 years ago

0.800.0

3 years ago

0.800.0-rc.4

3 years ago

0.800.0-rc.3

3 years ago

0.13.9

3 years ago

0.800.0-rc.2

3 years ago

0.800.0-rc.1

3 years ago

0.800.0-rc.0

3 years ago

0.800.0-beta.18

3 years ago

0.800.0-beta.17

3 years ago

0.800.0-beta.16

3 years ago

0.800.0-beta.15

3 years ago

0.800.0-beta.14

3 years ago

0.800.0-beta.13

3 years ago

0.800.0-beta.12

3 years ago

0.800.0-beta.11

3 years ago

0.13.8

3 years ago

0.800.0-beta.10

3 years ago

0.13.7

3 years ago

0.800.0-beta.9

4 years ago

0.800.0-beta.8

4 years ago

0.800.0-beta.7

4 years ago

0.13.6

4 years ago

0.800.0-beta.6

4 years ago

0.13.5

4 years ago

0.14.0-beta.5

4 years ago

0.13.4

4 years ago

0.14.0-beta.4

4 years ago

0.14.0-beta.2

4 years ago

0.13.3

4 years ago

0.14.0-beta.1

4 years ago

0.13.2

4 years ago

0.13.1

4 years ago

0.14.0-beta.0

4 years ago

0.13.0

4 years ago

0.12.4

4 years ago

0.13.0-rc.0

4 years ago

0.12.3

4 years ago

0.12.2

4 years ago

0.13.0-beta.0

4 years ago

0.12.1

4 years ago

0.12.0

4 years ago

0.8.9

4 years ago

0.12.0-rc.0

4 years ago

0.11.4

4 years ago

0.12.0-beta.2

4 years ago

0.11.3

4 years ago

0.12.0-beta.1

4 years ago

0.11.2

4 years ago

0.11.1

4 years ago

0.12.0-beta.0

4 years ago

0.8.8

4 years ago

0.11.0

4 years ago

0.10.7

4 years ago

0.11.0-rc.0

4 years ago

0.10.6

4 years ago

0.10.5

4 years ago

0.11.0-beta.1

4 years ago

0.8.7

4 years ago

0.11.0-beta.0

4 years ago

0.10.4

4 years ago

0.10.3

4 years ago

0.8.6

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.8.5

4 years ago

0.9.0-rc.3

4 years ago

0.9.0-rc.2

4 years ago

0.9.0-rc.1

4 years ago

0.8.4

4 years ago

0.6.0-rc.0

4 years ago

0.9.0-rc.0

4 years ago

0.9.0-beta.4

4 years ago

0.8.3

4 years ago

0.9.0-beta.3

4 years ago

0.8.2

4 years ago

0.9.0-beta.2

4 years ago

0.9.0-beta.1

4 years ago

0.9.0-beta.0

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.8.0-rc.1

4 years ago

0.8.0-rc.0

4 years ago

0.7.5

4 years ago

0.7.4

4 years ago

0.8.0-beta.3

4 years ago

0.8.0-beta.2

4 years ago

0.7.3

4 years ago

0.8.0-beta.1

4 years ago

0.8.0-beta.0

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.7.0-rc.3

4 years ago

0.7.0-rc.2

4 years ago

0.7.0-rc.1

4 years ago

0.7.0-rc.0

4 years ago

0.7.0-beta.2

4 years ago

0.6.8

4 years ago

0.7.0-beta.1

4 years ago

0.7.0-beta.0

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.13

4 years ago

0.5.12

4 years ago

0.5.11

4 years ago

0.5.10

4 years ago

0.5.9

4 years ago

0.5.8

4 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.5

4 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.9

4 years ago

0.4.8

4 years ago

0.4.7

4 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.3.2

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.38

5 years ago

0.0.37

5 years ago

0.0.36

5 years ago

0.0.35

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago