Skip to content

Instantly share code, notes, and snippets.

View arturovt's full-sized avatar
🎯

Artur arturovt

🎯
View GitHub Profile
// https://github.com/angular/angular-cli/blob/bd040bd4d6d2f69b49cf7e343829027e5dbfc73d/packages/ngtools/webpack/src/ivy/transformation.ts#L14-L34
export function createAotTransformers(
builder: ts.BuilderProgram,
options: { emitClassMetadata?: boolean; emitNgModuleScope?: boolean },
): ts.CustomTransformers {
const getTypeChecker = () => builder.getProgram().getTypeChecker();
const transformers: ts.CustomTransformers = {
before: [replaceBootstrap(getTypeChecker)],
after: [],
};
export default (config: webpack.Configuration) => {
if (config.mode === 'production') {
const transformation = require('@ngtools/webpack/src/ivy/transformation');
const createAotTransformers = transformation.createAotTransformers;
transformation.createAotTransformers = function () {
const transformers: ts.CustomTransformers = createAotTransformers(...arguments);
transformers.before!.push(replaceIsPlatformCallsTransformerFactory);
return transformers;
};
class ArticleComponent {
constructor(t, e) {
this.article$ = t.params.pipe(
Object(i.a)(t => {
const o = Object(c.d)(`article:${t.id}`);
return e.get(o, null);
}),
);
}
}
import { ɵɵdirectiveInject as directiveInject } from '@angular/core';
export class ArticleComponent {
article$: Observable<Article>;
constructor(route: ActivatedRoute, transferState: TransferState) {
if (isPlatformServer(directiveInject(PLATFORM_ID))) {
const meta = directiveInject(Meta);
const http = directiveInject(HttpClient);
class ArticleComponent {
constructor(t, e, o, n, r) {
this.article$ = e.params.pipe(
Object(l.a)(t => {
const e = Object(i.e)(`article:${t.id}`);
return r.get(e, null);
}),
);
}
}
import * as ts from 'typescript';
const replaceIsPlatformCallsTransformerFactory: ts.TransformerFactory<ts.SourceFile> = (
context: ts.TransformationContext,
) => (sourceFile: ts.SourceFile) => {
const visitCallExpression: ts.Visitor = (node: ts.Node) => {
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
// If it's a call expression like `isPlatformServer(platformId)`.
if (node.expression.escapedText === 'isPlatformServer') {
return ts.factory.createFalse();
import * as ts from 'typescript';
import * as webpack from 'webpack';
import { AngularCompilerPlugin, PLATFORM } from '@ngtools/webpack';
const replaceIsPlatformCallsTransformerFactory: ts.TransformerFactory<ts.SourceFile> = (
context: ts.TransformationContext,
) => (sourceFile: ts.SourceFile) => {
const visitCallExpression: ts.Visitor = (node: ts.Node) => {
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
// If it's a call expression like `isPlatformServer(platformId)`.
import * as ts from 'typescript';
import { PLATFORM } from '@ngtools/webpack';
const replaceIsPlatformCallsTransformerFactory: ts.TransformerFactory<ts.SourceFile> = (
context: ts.TransformationContext,
) => (sourceFile: ts.SourceFile) => {
const visitCallExpression: ts.Visitor = (node: ts.Node) => {
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
// If it's a call expression like `isPlatformServer(platformId)`.
if (node.expression.escapedText === 'isPlatformServer') {
import * as ts from 'typescript';
const transformerFactory: ts.TransformerFactory<ts.SourceFile> = (
context: ts.TransformationContext,
) => {
return (sourceFile: ts.SourceFile) => {
const someVisitFunction: ts.Visitor = (node: ts.Node) => {
if (ts.isFunctionDeclaration(node)) {
console.log('Whooah, it is a function declaration!');
}
import * as webpack from 'webpack';
export default (config: webpack.Configuration) => {
return config;
};