Skip to content

Commit

Permalink
feat: outputOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed Aug 16, 2022
1 parent 1de1fc4 commit 7816aa5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parse as parseUrl } from 'node:url'
import fs, { promises as fsp } from 'node:fs'
import * as mrmime from 'mrmime'
import type {
NormalizedOutputOptions,
OutputOptions,
PluginContext,
PreRenderedAsset,
Expand Down Expand Up @@ -45,6 +46,7 @@ export function renderAssetUrl(
ctx: PluginContext,
config: ResolvedConfig,
chunk: RenderedChunk,
outputOptions: NormalizedOutputOptions,
code: string,
assetFileName: string,
hostType: 'js' | 'css' | 'html',
Expand Down Expand Up @@ -83,6 +85,7 @@ export function renderAssetUrl(
assetFileName,
hostType,
config,
outputOptions.format,
toAssetsRelative
)
const replacementString =
Expand All @@ -107,6 +110,7 @@ export function renderAssetUrl(
assetFileName,
hostType,
config,
outputOptions.format,
toPublicAssetsRelative
? (filename, hostType) =>
toPublicAssetsRelative(publicUrl, filename, hostType)
Expand Down Expand Up @@ -178,8 +182,16 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
return `export default ${JSON.stringify(url)}`
},

renderChunk(code, chunk) {
const s = renderAssetUrl(this, config, chunk, code, chunk.fileName, 'js')
renderChunk(code, chunk, outputOptions) {
const s = renderAssetUrl(
this,
config,
chunk,
outputOptions,
code,
chunk.fileName,
'js'
)
if (s) {
return {
code: s.toString(),
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
config,
chunk,
chunkCSS,
opts,
cssAssetName,
'css',
toRelative,
Expand Down

0 comments on commit 7816aa5

Please sign in to comment.