From b02ad7ada8f8a7c4e02e54f61b7cec23daf33fc8 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 27 Jun 2022 14:02:17 +0200 Subject: [PATCH] refactor: rename to renderBuiltUrl --- docs/guide/build.md | 6 +++--- packages/plugin-legacy/src/index.ts | 6 +++--- packages/vite/src/node/build.ts | 12 ++++++------ packages/vite/src/node/config.ts | 2 +- packages/vite/src/node/plugins/asset.ts | 4 ++-- playground/assets/vite.config-runtime-base.js | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/guide/build.md b/docs/guide/build.md index 9813bbbd7011a6..4df81b56fe34fa 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -197,11 +197,11 @@ A user may choose to deploy in three different paths: - The generated hashed assets (JS, CSS, and other file types like images) - The copied [public files](assets.md#the-public-directory) -A single static [base](#public-base-path) isn't enough in these scenarios. Vite provides experimental support for advanced base options during build, using `experimental.renderBuiltAssetUrl`. +A single static [base](#public-base-path) isn't enough in these scenarios. Vite provides experimental support for advanced base options during build, using `experimental.renderBuiltUrl`. ```js experimental: { - renderBuiltAssetUrl: (filename: string, importer: string) => { + renderBuiltUrl: (filename: string, importer: string) => { if (path.extname(importer) === '.js') { return { runtime: `window.__toCdnUrl(${JSON.stringify(filename)})` } } else { @@ -215,7 +215,7 @@ If the hashed assets and public files aren't deployed together, options for each ```js experimental: { - renderBuiltAssetUrl(filename: string, importer: string, { type: 'public' | 'asset' }) { + renderBuiltUrl(filename: string, importer: string, { type: 'public' | 'asset' }) { if (type === 'public') { return 'https://www.domain.com/' + filename } diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index 50fc7d0d5d054c..a4aa34a2fc0672 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -40,10 +40,10 @@ function toOutputFilePathInHtml( config: ResolvedConfig, toRelative: (filename: string, importer: string) => string ): string { - const { renderBuiltAssetUrl } = config.experimental + const { renderBuiltUrl } = config.experimental let relative = config.base === '' || config.base === './' - if (renderBuiltAssetUrl) { - const result = renderBuiltAssetUrl(filename, importer, { + if (renderBuiltUrl) { + const result = renderBuiltUrl(filename, importer, { type, ssr: !!config.build.ssr }) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 61cace4c6d2642..80c925b991e5a4 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -847,10 +847,10 @@ export function toOutputFilePathInString( importer: string ) => string | { runtime: string } ): string | { runtime: string } { - const { renderBuiltAssetUrl } = config.experimental + const { renderBuiltUrl } = config.experimental let relative = config.base === '' || config.base === './' - if (renderBuiltAssetUrl) { - const result = renderBuiltAssetUrl(filename, importer, { + if (renderBuiltUrl) { + const result = renderBuiltUrl(filename, importer, { type, ssr: !!config.build.ssr }) @@ -878,10 +878,10 @@ export function toOutputFilePathWithoutRuntime( config: ResolvedConfig, toRelative: (filename: string, importer: string) => string ): string { - const { renderBuiltAssetUrl } = config.experimental + const { renderBuiltUrl } = config.experimental let relative = config.base === '' || config.base === './' - if (renderBuiltAssetUrl) { - const result = renderBuiltAssetUrl(filename, importer, { + if (renderBuiltUrl) { + const result = renderBuiltUrl(filename, importer, { type, ssr: !!config.build.ssr }) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 91be93cb539da7..242cd3fb580d37 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -259,7 +259,7 @@ export interface ExperimentalOptions { * * @experimental */ - renderBuiltAssetUrl?: RenderBuiltAssetUrl + renderBuiltUrl?: RenderBuiltAssetUrl /** * Enables support of HMR partial accept via `import.meta.hot.acceptExports`. * diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 68ef4a2d8da13a..ae8ee18103d98a 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -347,7 +347,7 @@ export function publicFileToBuiltUrl( config: ResolvedConfig ): string { if (config.command !== 'build') { - // We don't need relative base or renderBuiltAssetUrl support during dev + // We don't need relative base or renderBuiltUrl support during dev return config.base + url.slice(1) } const hash = getHash(url) @@ -428,7 +428,7 @@ async function fileToBuiltUrl( emittedSet.add(contentHash) } - url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}` + url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}` // TODO_BASE } cache.set(id, url) diff --git a/playground/assets/vite.config-runtime-base.js b/playground/assets/vite.config-runtime-base.js index a9b66e3e181e2e..f9033dc70cc2ee 100644 --- a/playground/assets/vite.config-runtime-base.js +++ b/playground/assets/vite.config-runtime-base.js @@ -45,7 +45,7 @@ module.exports = { } ], experimental: { - renderBuiltAssetUrl(filename, importer, { type }) { + renderBuiltUrl(filename, importer, { type }) { if (type === 'asset') { if (path.extname(importer) === '.js') { return {