Giter Club home page Giter Club logo

angular-devkit-build-optimizer-builds's Introduction

Snapshot build of @angular-devkit/build-optimizer

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.git

Angular Build Optimizer

Angular 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.

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

angular-devkit-build-optimizer-builds's People

Contributors

hansl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.