diff --git a/projects/core-ui/schematics/html-utils.ts b/projects/core-ui/schematics/html-utils.ts
index 87d40c627..832034d8d 100644
--- a/projects/core-ui/schematics/html-utils.ts
+++ b/projects/core-ui/schematics/html-utils.ts
@@ -1,8 +1,11 @@
-const RewritingStream = require('parse5-html-rewriting-stream');
-import { Rule, SchematicContext, SchematicsException } from '@angular-devkit/schematics';
+import { Rule, SchematicContext, SchematicsException, } from '@angular-devkit/schematics';
import { Tree } from '@angular-devkit/schematics/src/tree/interface';
import { Readable, Writable } from 'stream';
+export function loadEsmModule(modulePath: string | URL): Promise {
+ return new Function('modulePath', `return import(modulePath);`)(modulePath) as Promise;
+}
+
interface Iparse5Tag {
tagName: string;
attrs: [];
@@ -22,13 +25,17 @@ interface Iparse5Tag {
* https://github.com/angular/angular-cli/blob/aedfcc1862afc599ea18c578248d0aa373a947bb/packages/angular_devkit/build_angular/src/utils/index-file/html-rewriting-stream.ts#L11
*/
export function updateHtmlFile(path: string, startTagStr: string, endTagStr: string, items: string | string[]): Rule {
- return (tree: Tree, context: SchematicContext) => {
+ return async (tree: Tree, context: SchematicContext) => {
const buffer = tree.read(path);
if (buffer === null) {
throw new SchematicsException(`Could not read index file: ${path}`);
}
+ const { RewritingStream } = await loadEsmModule(
+ 'parse5-html-rewriting-stream',
+ );
+
const rewriter = new RewritingStream();
const startTags: Iparse5Tag[] = [];
rewriter.on('startTag', (startTag: Iparse5Tag) => {