UNPKG

3.04 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { AngularCompilerPluginOptions } from '@ngtools/webpack';
3export declare type BeforeRunHandler = (resourceCompiler: {
4 get(filename: string): Promise<string>;
5}) => void | Promise<void>;
6export declare type ResourcePathTransformer = (path: string) => string;
7export declare type ResourceTransformer = (path: string, source: string) => string | Promise<string>;
8export declare type ReadFileTransformer = {
9 predicate: RegExp | ((path: string) => boolean);
10 transform: (path: string, source: string) => string;
11};
12export interface NgcWebpackPluginOptions extends AngularCompilerPluginOptions {
13 /**
14 * An alias for `AngularCompilerPluginOptions.skipCodeGeneration` simply to make it more readable.
15 * If `skipCodeGeneration` is set, this value is ignored.
16 * If this value is not set, the default value is taken from `skipCodeGeneration`
17 * (which means AOT = true)
18 */
19 AOT?: boolean;
20 /**
21 * A hook that invokes before the plugin start the compilation process (compiler 'run' event).
22 * ( resourceCompiler: { get(filename: string): Promise<string> }) => Promise<void>;
23 *
24 * The hook accepts a resource compiler which able (using webpack) to perform compilation on
25 * files using webpack's loader chain and return the final content.
26 * @param resourceCompiler
27 */
28 beforeRun?: BeforeRunHandler;
29 /**
30 * Transform a source file (ts, js, metadata.json, summery.json).
31 * If `predicate` is true invokes `transform`
32 *
33 * > Run's in both AOT and JIT mode on all files, internal and external as well as resources.
34 *
35 *
36 * - Do not apply changes to resource files using this hook when in AOT mode, it will not commit.
37 * - Do not apply changes to resource files in watch mode.
38 *
39 * Note that source code transformation is sync, you can't return a promise (contrary to `resourcePathTransformer`).
40 * This means that you can not use webpack compilation (or any other async process) to alter source code context.
41 * If you know the files you need to transform, use the `beforeRun` hook.
42 */
43 readFileTransformer?: ReadFileTransformer;
44 /**
45 * Transform the path of a resource (html, css, etc)
46 * (path: string) => string;
47 *
48 * > Run's in AOT mode only and on metadata resource files (templateUrl, styleUrls)
49 */
50 resourcePathTransformer?: ResourcePathTransformer;
51 /**
52 * Transform a resource (html, css etc)
53 * (path: string, source: string) => string | Promise<string>;
54 *
55 * > Run's in AOT mode only and on metadata resource files (templateUrl, styleUrls)
56 */
57 resourceTransformer?: ResourceTransformer;
58 /**
59 * Add custom TypeScript transformers to the compilation process.
60 *
61 * Transformers are applied after the transforms added by `@angular/compiler-cli` and
62 * `@ngtools/webpack`.
63 *
64 * > `after` transformers are currently not supported.
65 */
66 tsTransformers?: ts.CustomTransformers;
67}