Skip to content

Commit 5a2a963

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): bypass Vite prebundling for absolute URL imports
To avoid the Vite-based development server's prebundling system from attempting to prebundle import statements containing absolute URLs, the set of external specifiers will now be pre-filtered before being passed onto Vite. Currently, the check for an absolute URL is any specifier starting with `http://`, `https://`, or '//'.
1 parent 3056ccd commit 5a2a963

File tree

1 file changed

+7
-2
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+7
-2
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,13 @@ export async function* serveWithVite(
206206
externalMetadata.implicitBrowser.length = 0;
207207

208208
externalMetadata.explicit.push(...explicit);
209-
externalMetadata.implicitServer.push(...implicitServer);
210-
externalMetadata.implicitBrowser.push(...implicitBrowser);
209+
// Remove any absolute URLs (http://, https://, //) to avoid Vite's prebundling from processing them as files
210+
externalMetadata.implicitServer.push(
211+
...(implicitServer as string[]).filter((value) => !/^(?:https?:)?\/\//.test(value)),
212+
);
213+
externalMetadata.implicitBrowser.push(
214+
...(implicitBrowser as string[]).filter((value) => !/^(?:https?:)?\/\//.test(value)),
215+
);
211216

212217
// The below needs to be sorted as Vite uses these options are part of the hashing invalidation algorithm.
213218
// See: https://github.com/vitejs/vite/blob/0873bae0cfe0f0718ad2f5743dd34a17e4ab563d/packages/vite/src/node/optimizer/index.ts#L1203-L1239

0 commit comments

Comments
 (0)