Ignore embedded image as page dependency during build (#1053)
This commit is contained in:
parent
8e7c5ef991
commit
cb43ca440b
1 changed files with 8 additions and 9 deletions
|
@ -32,10 +32,9 @@ async function allPages(root: URL): Promise<URL[]> {
|
||||||
return files.map((f) => new URL(f, root));
|
return files.map((f) => new URL(f, root));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Is this URL remote? */
|
/** Is this URL remote or embedded? */
|
||||||
function isRemote(url: string) {
|
function isRemoteOrEmbedded(url: string) {
|
||||||
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) return true;
|
return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//') || url.startsWith('data:');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The primary build action */
|
/** The primary build action */
|
||||||
|
@ -268,7 +267,7 @@ export function findDeps(html: string, { astroConfig, srcPath }: { astroConfig:
|
||||||
$('script').each((_i, el) => {
|
$('script').each((_i, el) => {
|
||||||
const src = $(el).attr('src');
|
const src = $(el).attr('src');
|
||||||
if (src) {
|
if (src) {
|
||||||
if (isRemote(src)) return;
|
if (isRemoteOrEmbedded(src)) return;
|
||||||
pageDeps.js.add(getDistPath(src, { astroConfig, srcPath }));
|
pageDeps.js.add(getDistPath(src, { astroConfig, srcPath }));
|
||||||
} else {
|
} else {
|
||||||
const text = $(el).html();
|
const text = $(el).html();
|
||||||
|
@ -276,7 +275,7 @@ export function findDeps(html: string, { astroConfig, srcPath }: { astroConfig:
|
||||||
const [imports] = eslexer.parse(text);
|
const [imports] = eslexer.parse(text);
|
||||||
for (const spec of imports) {
|
for (const spec of imports) {
|
||||||
const importSrc = spec.n;
|
const importSrc = spec.n;
|
||||||
if (importSrc && !isRemote(importSrc)) {
|
if (importSrc && !isRemoteOrEmbedded(importSrc)) {
|
||||||
pageDeps.js.add(getDistPath(importSrc, { astroConfig, srcPath }));
|
pageDeps.js.add(getDistPath(importSrc, { astroConfig, srcPath }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,7 +284,7 @@ export function findDeps(html: string, { astroConfig, srcPath }: { astroConfig:
|
||||||
|
|
||||||
$('link[href]').each((_i, el) => {
|
$('link[href]').each((_i, el) => {
|
||||||
const href = $(el).attr('href');
|
const href = $(el).attr('href');
|
||||||
if (href && !isRemote(href) && ($(el).attr('rel') === 'stylesheet' || $(el).attr('type') === 'text/css' || href.endsWith('.css'))) {
|
if (href && !isRemoteOrEmbedded(href) && ($(el).attr('rel') === 'stylesheet' || $(el).attr('type') === 'text/css' || href.endsWith('.css'))) {
|
||||||
const dist = getDistPath(href, { astroConfig, srcPath });
|
const dist = getDistPath(href, { astroConfig, srcPath });
|
||||||
pageDeps.css.add(dist);
|
pageDeps.css.add(dist);
|
||||||
}
|
}
|
||||||
|
@ -293,7 +292,7 @@ export function findDeps(html: string, { astroConfig, srcPath }: { astroConfig:
|
||||||
|
|
||||||
$('img[src]').each((_i, el) => {
|
$('img[src]').each((_i, el) => {
|
||||||
const src = $(el).attr('src');
|
const src = $(el).attr('src');
|
||||||
if (src && !isRemote(src)) {
|
if (src && !isRemoteOrEmbedded(src)) {
|
||||||
pageDeps.images.add(getDistPath(src, { astroConfig, srcPath }));
|
pageDeps.images.add(getDistPath(src, { astroConfig, srcPath }));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -303,7 +302,7 @@ export function findDeps(html: string, { astroConfig, srcPath }: { astroConfig:
|
||||||
const sources = srcset.split(',');
|
const sources = srcset.split(',');
|
||||||
const srces = sources.map((s) => s.trim().split(' ')[0]);
|
const srces = sources.map((s) => s.trim().split(' ')[0]);
|
||||||
for (const src of srces) {
|
for (const src of srces) {
|
||||||
if (!isRemote(src)) {
|
if (!isRemoteOrEmbedded(src)) {
|
||||||
pageDeps.images.add(getDistPath(src, { astroConfig, srcPath }));
|
pageDeps.images.add(getDistPath(src, { astroConfig, srcPath }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue