Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): bypass Vite prebundling for absol…
Browse files Browse the repository at this point in the history
…ute 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 '//'.

(cherry picked from commit 5a2a963)
  • Loading branch information
clydin authored and alan-agius4 committed Feb 12, 2024
1 parent 6d2168d commit bf42d6d
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -206,8 +206,13 @@ export async function* serveWithVite(
externalMetadata.implicitBrowser.length = 0;

externalMetadata.explicit.push(...explicit);
externalMetadata.implicitServer.push(...implicitServer);
externalMetadata.implicitBrowser.push(...implicitBrowser);
// Remove any absolute URLs (http://, https://, //) to avoid Vite's prebundling from processing them as files
externalMetadata.implicitServer.push(
...(implicitServer as string[]).filter((value) => !/^(?:https?:)?\/\//.test(value)),
);
externalMetadata.implicitBrowser.push(
...(implicitBrowser as string[]).filter((value) => !/^(?:https?:)?\/\//.test(value)),
);

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

0 comments on commit bf42d6d

Please sign in to comment.