Skip to content

Instantly share code, notes, and snippets.

@nitedani
Created September 18, 2022 02:40
Show Gist options
  • Save nitedani/b13584a4596ddc4b735b91ac1b2f0b39 to your computer and use it in GitHub Desktop.
Save nitedani/b13584a4596ddc4b735b91ac1b2f0b39 to your computer and use it in GitHub Desktop.
Compile angular components
import { NgtscProgram, readConfiguration } from '@angular/compiler-cli';
import { dirname, resolve } from 'path';
import ts from 'typescript';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const { options, rootNames } = readConfiguration(
resolve(__dirname, '..', 'tsconfig.angular.json')
);
const host = ts.createIncrementalCompilerHost(options);
const program = new NgtscProgram(rootNames, options, host);
const ngtsc = program.getTsProgram();
const transformers = program.compiler.prepareEmit().transformers;
for (const r of rootNames) {
const file = ngtsc.getSourceFile(r);
ngtsc.emit(file, undefined, undefined, undefined, transformers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment