ngc-webpack

  • Version 4.1.2
  • Published
  • 9 dependencies
  • MIT license

Install

npm i ngc-webpack
yarn add ngc-webpack
pnpm add ngc-webpack

Overview

A wrapper for the @ngtools/webpack with hooks into the compilation process

Index

Functions

function createAngularCompilerPluginExecutionHost

createAngularCompilerPluginExecutionHost: (
options: NgcWebpackPluginOptions
) => NgcCompilerExecutionHost;

    function runCli

    runCli: {
    (webpackConfig: string | webpack.Configuration): Promise<ParsedDiagnostics>;
    (
    webpackConfig: any,
    cliParams: { args: string[]; parsedArgs?: any }
    ): Promise<ParsedDiagnostics>;
    (
    webpackConfig: any,
    tsConfigPath: string,
    cliParams?: { args: string[]; parsedArgs?: any }
    ): Promise<ParsedDiagnostics>;
    };
    • Run ngc-webpack in library mode. (i.e. run ngc) In Library mode compilation and output is done per module and no bundling is done. Webpack is used for resource compilation through it's loader chain but does not bundle anything. The webpack configuration, excluding loaders, has no effect. The webpack configuration must include a plugin instance (either NgcWebpackPlugin / AngularCompilerPlugin).

      Library mode configuration is done mainly from the tsconfig json file.

      tsconfig json path is taken from the options of NgcWebpackPlugin / AngularCompilerPlugin

      Parameter webpackConfig

      Webpack configuration module, object or string

    • Run ngc-webpack in library mode. (i.e. run ngc) In Library mode compilation and output is done per module and no bundling is done. Webpack is used for resource compilation through it's loader chain but does not bundle anything. The webpack configuration, excluding loaders, has no effect. The webpack configuration must include a plugin instance (either NgcWebpackPlugin / AngularCompilerPlugin).

      Library mode configuration is done mainly from the tsconfig json file.

      tsconfig json path is taken from cli parameters (-p or --project) or, if not exists the options of NgcWebpackPlugin / AngularCompilerPlugin

      Parameter webpackConfig

      Webpack configuration module, object or string,

      Parameter cliParams

      cli Parameters, parsedArgs is not mandatory

    • Run ngc-webpack in library mode. (i.e. run ngc) In Library mode compilation and output is done per module and no bundling is done. Webpack is used for resource compilation through it's loader chain but does not bundle anything. The webpack configuration, excluding loaders, has no effect. The webpack configuration must include a plugin instance (either NgcWebpackPlugin / AngularCompilerPlugin).

      Library mode configuration is done mainly from the tsconfig json file.

      tsconfig json path is taken from the supplied tsConfigPath parameter.

      Parameter webpackConfig

      Webpack configuration module, object or string,

      Parameter tsConfigPath

      path to the tsconfig file, relative to process.cwd()

      Parameter cliParams

      cli Parameters, parsedArgs is not mandatory

    function runNgCli

    runNgCli: {
    (): Promise<ParsedDiagnostics>;
    (cliParams: { args: string[]; parsedArgs?: any }): Promise<ParsedDiagnostics>;
    (
    tsConfigPath: string,
    cliParams?: { args: string[]; parsedArgs?: any }
    ): Promise<ParsedDiagnostics>;
    };
    • Run ngc-webpack in library mode (i.e. run ngc) using @angular/cli (ng) configuration. The cli is used to create a live instance of the webpack configuration, from there it is the same process as [[runCli]]

      tsconfig json path is taken from the options of AngularCompilerPlugin

      > This is not recommended, you would normally want to provide your own tsconfig with proper angularCompilerOptions.

    • Run ngc-webpack in library mode (i.e. run ngc) using @angular/cli (ng) configuration. The cli is used to create a live instance of the webpack configuration, from there it is the same process as [[runCli]]

      tsconfig json path is taken from cli parameters (-p or --project) or, if not exists the options of AngularCompilerPlugin

      Parameter cliParams

      cli Parameters, parsedArgs is not mandatory

    • Run ngc-webpack in library mode (i.e. run ngc) using @angular/cli (ng) configuration. The cli is used to create a live instance of the webpack configuration, from there it is the same process as [[runCli]]

      tsconfig json path is taken from the supplied tsConfigPath parameter.

      Parameter tsConfigPath

      Parameter cliParams

      cli Parameters, parsedArgs is not mandatory

    Classes

    class NgcWebpackPlugin

    class NgcWebpackPlugin {}

      constructor

      constructor(
      options: NgcWebpackPluginOptions,
      executionHostFactory?: (
      options: NgcWebpackPluginOptions
      ) => NgcCompilerExecutionHost
      );

        property ngcWebpackPluginOptions

        readonly ngcWebpackPluginOptions: NgcWebpackPluginOptions;

          method apply

          apply: (compiler: any) => void;

            method clone

            static clone: (
            plugin: NgcWebpackPlugin,
            overwrite: {
            options?: Partial<NgcWebpackPluginOptions>;
            executionHostFactory?: (
            options: NgcWebpackPluginOptions
            ) => NgcCompilerExecutionHost;
            }
            ) => NgcWebpackPlugin;

              Interfaces

              interface NgcCompilerExecutionHost

              interface NgcCompilerExecutionHost {}

                property compilerHost

                compilerHost: NgcCompilerHost;

                  property hookOverride

                  hookOverride?: {
                  [K in keyof NgcWebpackPluginOptions]?: (
                  opt: NgcWebpackPluginOptions[K]
                  ) => void;
                  };

                    property transformers

                    transformers: ts.TransformerFactory<ts.SourceFile>[];

                      method execute

                      execute: (compiler: any) => void;

                        interface NgcCompilerHost

                        interface NgcCompilerHost extends ts.CompilerHost {}

                          property resourceLoader

                          resourceLoader?: {
                          get(filePath: string): Promise<string>;
                          };

                            method readResource

                            readResource: (fileName: string) => Promise<string> | string;

                              interface NgcWebpackPluginOptions

                              interface NgcWebpackPluginOptions extends AngularCompilerPluginOptions {}

                                property AOT

                                AOT?: boolean;
                                • An alias for AngularCompilerPluginOptions.skipCodeGeneration simply to make it more readable. If skipCodeGeneration is set, this value is ignored. If this value is not set, the default value is taken from skipCodeGeneration (which means AOT = true)

                                property beforeRun

                                beforeRun?: BeforeRunHandler;
                                • A hook that invokes before the plugin start the compilation process (compiler 'run' event). ( resourceCompiler: { get(filename: string): Promise }) => Promise;

                                  The hook accepts a resource compiler which able (using webpack) to perform compilation on files using webpack's loader chain and return the final content.

                                  Parameter resourceCompiler

                                property readFileTransformer

                                readFileTransformer?: ReadFileTransformer;
                                • Transform a source file (ts, js, metadata.json, summery.json). If predicate is true invokes transform

                                  > Run's in both AOT and JIT mode on all files, internal and external as well as resources.

                                  - Do not apply changes to resource files using this hook when in AOT mode, it will not commit. - Do not apply changes to resource files in watch mode.

                                  Note that source code transformation is sync, you can't return a promise (contrary to resourcePathTransformer). This means that you can not use webpack compilation (or any other async process) to alter source code context. If you know the files you need to transform, use the beforeRun hook.

                                property resourcePathTransformer

                                resourcePathTransformer?: ResourcePathTransformer;
                                • Transform the path of a resource (html, css, etc) (path: string) => string;

                                  > Run's in AOT mode only and on metadata resource files (templateUrl, styleUrls)

                                property resourceTransformer

                                resourceTransformer?: ResourceTransformer;
                                • Transform a resource (html, css etc) (path: string, source: string) => string | Promise;

                                  > Run's in AOT mode only and on metadata resource files (templateUrl, styleUrls)

                                property tsTransformers

                                tsTransformers?: ts.CustomTransformers;
                                • Add custom TypeScript transformers to the compilation process.

                                  Transformers are applied after the transforms added by @angular/compiler-cli and @ngtools/webpack.

                                  > after transformers are currently not supported.

                                Type Aliases

                                type BeforeRunHandler

                                type BeforeRunHandler = (resourceCompiler: {
                                get(filename: string): Promise<string>;
                                }) => void | Promise<void>;

                                  type ReadFileTransformer

                                  type ReadFileTransformer = {
                                  predicate: RegExp | ((path: string) => boolean);
                                  transform: (path: string, source: string) => string;
                                  };

                                    type ResourcePathTransformer

                                    type ResourcePathTransformer = (path: string) => string;

                                      type ResourceTransformer

                                      type ResourceTransformer = (
                                      path: string,
                                      source: string
                                      ) => string | Promise<string>;

                                        Package Files (5)

                                        Dependencies (9)

                                        Dev Dependencies (49)

                                        Peer Dependencies (2)

                                        Badge

                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ngc-webpack.

                                        • Markdown
                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/ngc-webpack)
                                        • HTML
                                          <a href="https://www.jsdocs.io/package/ngc-webpack"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>