Skip to content

Commit

Permalink
refactor: rename to renderBuiltUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jun 27, 2022
1 parent eb6eb61 commit b02ad7a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions docs/guide/build.md
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-legacy/src/index.ts
Expand Up @@ -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
})
Expand Down
12 changes: 6 additions & 6 deletions packages/vite/src/node/build.ts
Expand Up @@ -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
})
Expand Down Expand Up @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Expand Up @@ -259,7 +259,7 @@ export interface ExperimentalOptions {
*
* @experimental
*/
renderBuiltAssetUrl?: RenderBuiltAssetUrl
renderBuiltUrl?: RenderBuiltAssetUrl
/**
* Enables support of HMR partial accept via `import.meta.hot.acceptExports`.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/asset.ts
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion playground/assets/vite.config-runtime-base.js
Expand Up @@ -45,7 +45,7 @@ module.exports = {
}
],
experimental: {
renderBuiltAssetUrl(filename, importer, { type }) {
renderBuiltUrl(filename, importer, { type }) {
if (type === 'asset') {
if (path.extname(importer) === '.js') {
return {
Expand Down

0 comments on commit b02ad7a

Please sign in to comment.