diff options
-rw-r--r-- | packages/astro/src/vite-plugin-build-html/index.ts | 20 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-build-html/util.ts | 17 |
2 files changed, 21 insertions, 16 deletions
diff --git a/packages/astro/src/vite-plugin-build-html/index.ts b/packages/astro/src/vite-plugin-build-html/index.ts index 9a3254c93..139cc4051 100644 --- a/packages/astro/src/vite-plugin-build-html/index.ts +++ b/packages/astro/src/vite-plugin-build-html/index.ts @@ -114,9 +114,9 @@ export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin { frontEndImports.push(scriptId); astroScriptMap.set(scriptId, js); } - } else if(isInSrcDirectory(script, 'src', srcRoot, srcRootWeb)) { + } else if (isInSrcDirectory(script, 'src', srcRoot, srcRootWeb)) { const src = getAttribute(script, 'src'); - if(src) jsInput.add(src); + if (src) jsInput.add(src); } } @@ -347,17 +347,21 @@ export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin { ); } remove(script); - } else if(isInSrcDirectory(script, 'src', srcRoot, srcRootWeb)) { + } else if (isInSrcDirectory(script, 'src', srcRoot, srcRootWeb)) { const src = getAttribute(script, 'src'); // On windows the facadeId doesn't start with / but does not Unix :/ - if(src && (facadeIdMap.has(src) || facadeIdMap.has(src.substr(1)))) { + if (src && (facadeIdMap.has(src) || facadeIdMap.has(src.substr(1)))) { const assetRootPath = '/' + (facadeIdMap.get(src) || facadeIdMap.get(src.substr(1))); const relPath = npath.posix.relative(pathname, assetRootPath); const attrs = getAttributes(script); - insertBefore(script.parentNode, createScript({ - ...attrs, - src: relPath - }), script); + insertBefore( + script.parentNode, + createScript({ + ...attrs, + src: relPath, + }), + script + ); remove(script); } } diff --git a/packages/astro/src/vite-plugin-build-html/util.ts b/packages/astro/src/vite-plugin-build-html/util.ts index 585ba771f..4f7b48f26 100644 --- a/packages/astro/src/vite-plugin-build-html/util.ts +++ b/packages/astro/src/vite-plugin-build-html/util.ts @@ -1,4 +1,3 @@ - import { getAttribute, hasAttribute, getTagName } from '@web/parse5-utils'; import parse5 from 'parse5'; import { isStylesheetLink } from './extract-assets.js'; @@ -6,15 +5,17 @@ import { isStylesheetLink } from './extract-assets.js'; const tagsWithSrcSet = new Set(['img', 'source']); function startsWithSrcRoot(pathname: string, srcRoot: string, srcRootWeb: string): boolean { - return pathname.startsWith(srcRoot) // /Users/user/project/src/styles/main.css - || pathname.startsWith(srcRootWeb) // /src/styles/main.css - || `/${pathname}`.startsWith(srcRoot); // Windows fix: some paths are missing leading "/" + return ( + pathname.startsWith(srcRoot) || // /Users/user/project/src/styles/main.css + pathname.startsWith(srcRootWeb) || // /src/styles/main.css + `/${pathname}`.startsWith(srcRoot) + ); // Windows fix: some paths are missing leading "/" } export function isInSrcDirectory(node: parse5.Element, attr: string, srcRoot: string, srcRootWeb: string): boolean { const value = getAttribute(node, attr); return value ? startsWithSrcRoot(value, srcRoot, srcRootWeb) : false; -}; +} export function isAstroInjectedLink(node: parse5.Element): boolean { return isStylesheetLink(node) && getAttribute(node, 'data-astro-injected') === ''; @@ -31,10 +32,10 @@ export function isBuildableLink(node: parse5.Element, srcRoot: string, srcRootWe } return startsWithSrcRoot(href, srcRoot, srcRootWeb); -}; +} export function isBuildableImage(node: parse5.Element, srcRoot: string, srcRootWeb: string): boolean { - if(getTagName(node) === 'img') { + if (getTagName(node) === 'img') { const src = getAttribute(node, 'src'); return src ? startsWithSrcRoot(src, srcRoot, srcRootWeb) : false; } @@ -47,4 +48,4 @@ export function hasSrcSet(node: parse5.Element): boolean { export function isHoistedScript(node: parse5.Element): boolean { return getTagName(node) === 'script' && hasAttribute(node, 'hoist'); -}
\ No newline at end of file +} |