Home / File/ vite-plugin-assets.ts — astro Source File

vite-plugin-assets.ts — astro Source File

Architecture documentation for vite-plugin-assets.ts, a typescript file in the astro codebase. 21 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 21 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  7b37cc1c_ed73_6e29_d070_6510e98b551d["vite-plugin-assets.ts"]
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  d3861967_b647_84d2_ff48_15013353bd56["../core/logger/core.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> d3861967_b647_84d2_ff48_15013353bd56
  7e4494c0_5563_4329_1bff_a84be66e1bc2["../core/path.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> 7e4494c0_5563_4329_1bff_a84be66e1bc2
  a370a45c_02f1_30de_445d_47ee08d095a2["../core/viteUtils.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> a370a45c_02f1_30de_445d_47ee08d095a2
  f202f4fa_f9f9_9398_9510_7a42ce8ea007["../environments.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> f202f4fa_f9f9_9398_9510_7a42ce8ea007
  e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> e9b74c5a_8d34_34a7_e196_5e41b87214aa
  a19b6b68_b1f2_2d3e_2481_283031d370ff["./consts.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> a19b6b68_b1f2_2d3e_2481_283031d370ff
  a2fc192c_cdf9_df62_81bf_9c18a80b317e["./fonts/constants.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> a2fc192c_cdf9_df62_81bf_9c18a80b317e
  46fce977_13ea_1284_7c18_b2bd10dcf87b["./fonts/vite-plugin-fonts.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> 46fce977_13ea_1284_7c18_b2bd10dcf87b
  416eda3d_47e6_c298_102b_b7a37d86a44e["../../assets/types.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> 416eda3d_47e6_c298_102b_b7a37d86a44e
  617c63d5_1302_acd7_3e75_06534fb7e782["../../assets/utils/getAssetsPrefix.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> 617c63d5_1302_acd7_3e75_06534fb7e782
  24e4dd71_66ed_5d44_647a_f7752091bd7c["../../assets/utils/index.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> 24e4dd71_66ed_5d44_647a_f7752091bd7c
  db34c5eb_2288_0a98_b3b2_ee3c6260d741["../assets/utils/assets.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> db34c5eb_2288_0a98_b3b2_ee3c6260d741
  81ef02c8_27f0_6101_b479_46ceaa685c4c["../assets/utils/node.js"]
  7b37cc1c_ed73_6e29_d070_6510e98b551d --> 81ef02c8_27f0_6101_b479_46ceaa685c4c
  style 7b37cc1c_ed73_6e29_d070_6510e98b551d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type * as fsMod from 'node:fs';
import { extname } from 'node:path';
import MagicString from 'magic-string';
import type * as vite from 'vite';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import type { Logger } from '../core/logger/core.js';
import {
	appendForwardSlash,
	joinPaths,
	prependForwardSlash,
	removeBase,
	removeQueryString,
} from '../core/path.js';
import { normalizePath } from '../core/viteUtils.js';
import { isAstroServerEnvironment } from '../environments.js';
import type { AstroSettings } from '../types/astro.js';
import {
	RESOLVED_VIRTUAL_MODULE_ID,
	VALID_INPUT_FORMATS,
	VIRTUAL_MODULE_ID,
	VIRTUAL_SERVICE_ID,
} from './consts.js';
import { RUNTIME_VIRTUAL_MODULE_ID } from './fonts/constants.js';
import { fontsPlugin } from './fonts/vite-plugin-fonts.js';
import type { ImageTransform } from './types.js';
import { getAssetsPrefix } from './utils/getAssetsPrefix.js';
import { isESMImportedImage } from './utils/index.js';
import { emitClientAsset } from './utils/assets.js';
import { emitImageMetadata, hashTransform, propsToFilename } from './utils/node.js';
import { getProxyCode } from './utils/proxy.js';
import { makeSvgComponent } from './utils/svg.js';
import { createPlaceholderURL, stringifyPlaceholderURL } from './utils/url.js';

const assetRegex = new RegExp(`\\.(${VALID_INPUT_FORMATS.join('|')})`, 'i');
const assetRegexEnds = new RegExp(`\\.(${VALID_INPUT_FORMATS.join('|')})$`, 'i');
const addStaticImageFactory = (
	settings: AstroSettings,
): typeof globalThis.astroAsset.addStaticImage => {
	return (options, hashProperties, originalFSPath) => {
		if (!globalThis.astroAsset.staticImages) {
			globalThis.astroAsset.staticImages = new Map<
				string,
				{
					originalSrcPath: string;
					transforms: Map<string, { finalPath: string; transform: ImageTransform }>;
				}
			>();
		}

		// Rollup will copy the file to the output directory, as such this is the path in the output directory, including the asset prefix / base
		const ESMImportedImageSrc = isESMImportedImage(options.src) ? options.src.src : options.src;
		const fileExtension = extname(ESMImportedImageSrc);
		const assetPrefix = getAssetsPrefix(fileExtension, settings.config.build.assetsPrefix);

		// This is the path to the original image, from the dist root, without the base or the asset prefix (e.g. /_astro/image.hash.png)
		const finalOriginalPath = removeBase(
			removeBase(ESMImportedImageSrc, settings.config.base),
			assetPrefix,
		);

// ... (262 more lines)

Domain

Subdomains

Types

Dependencies

  • ../../assets/types.js
  • ../../assets/utils/getAssetsPrefix.js
  • ../../assets/utils/index.js
  • ../assets/utils/assets.js
  • ../assets/utils/node.js
  • ../assets/utils/proxy.js
  • ../core/errors/index.js
  • ../core/logger/core.js
  • ../core/path.js
  • ../core/viteUtils.js
  • ../environments.js
  • ../types/astro.js
  • ./consts.js
  • ./fonts/constants.js
  • ./fonts/vite-plugin-fonts.js
  • ./utils/svg.js
  • ./utils/url.js
  • magic-string
  • node:fs
  • node:path
  • vite

Frequently Asked Questions

What does vite-plugin-assets.ts do?
vite-plugin-assets.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in vite-plugin-assets.ts?
vite-plugin-assets.ts defines 2 function(s): addStaticImageFactory, assets.
What does vite-plugin-assets.ts depend on?
vite-plugin-assets.ts imports 21 module(s): ../../assets/types.js, ../../assets/utils/getAssetsPrefix.js, ../../assets/utils/index.js, ../assets/utils/assets.js, ../assets/utils/node.js, ../assets/utils/proxy.js, ../core/errors/index.js, ../core/logger/core.js, and 13 more.
Where is vite-plugin-assets.ts in the architecture?
vite-plugin-assets.ts is located at packages/astro/src/assets/vite-plugin-assets.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free