How to use the @ngtools/webpack/src/transformers.ReplaceNodeOperation function in @ngtools/webpack

To help you get started, we’ve selected a few @ngtools/webpack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NativeScript / nativescript-dev-webpack / transformers / ns-replace-bootstrap.ts View on Github external
),

                // Insert an import of the module factory in the beginning of the file:
                // import * as __NgCli_bootstrap_1 from "./app.module.ngfactory";
                ...insertStarImport(
                    sourceFile,
                    idNgFactory,
                    factoryModulePath,
                    firstNode,
                    true,
                ),

                // Replace the bootstrap call expression. For example:
                // from: platformNativeScriptDynamic().bootstrapModule(AppModule);
                // to:   platformNativeScript().bootstrapModuleFactory(__NgCli_bootstrap_2.AppModuleNgFactory);
                new ReplaceNodeOperation(sourceFile, bootstrapCallExpr, newBootstrapCallExpr),
            );
        });
github NativeScript / nativescript-dev-webpack / transformers / ns-support-hmr-ng.ts View on Github external
const acceptHmrNode = ts.createIdentifier(getAcceptMainModuleCode(appModulePath));

    const objectAssignNode = ts.createPropertyAccess(ts.createIdentifier("Object"), ts.createIdentifier("assign"));
    const extendAppOptionsNode = ts.createCall(objectAssignNode, undefined, [currentAppOptionsInitializationNode, ts.createIdentifier(GeneratedDynamicAppOptions)]);

    const newNsDynamicCallArgs = ts.createNodeArray([extendAppOptionsNode, ...nativeScriptPlatformCallNode.arguments.slice(1)]);
    const nsPlatformPath = findNativeScriptPlatformPathInSource(mainFile);
    const nsPlatformText = getExpressionName(nativeScriptPlatformCallNode.expression);
    const newNsDynamicCallNode = ts.createCall(ts.createPropertyAccess(ts.createIdentifier(NsNgPlatformStarImport), ts.createIdentifier(nsPlatformText)), [], newNsDynamicCallArgs);

    return [
        ...insertStarImport(mainFile, ts.createIdentifier(NsNgPlatformStarImport), nsPlatformPath, firstImportNode, true),
        new AddNodeOperation(mainFile, lastImportNode, undefined, optionsStatement),
        new AddNodeOperation(mainFile, lastImportNode, undefined, setHmrOptionsNode),
        new AddNodeOperation(mainFile, lastImportNode, undefined, acceptHmrNode),
        new ReplaceNodeOperation(mainFile, nativeScriptPlatformCallNode, newNsDynamicCallNode)
    ];
}