Skip to content

Commit

Permalink
fix: double export default for txt files
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jan 23, 2025
1 parent 07c25c6 commit 109dd05
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,12 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
const file = checkPublicFile(id, config) || cleanUrl(id)
this.addWatchFile(file)
// raw query, read file and return as string
return `export default ${JSON.stringify(
await fsp.readFile(file, 'utf-8'),
)}`
return {
code: `export default ${JSON.stringify(
await fsp.readFile(file, 'utf-8'),
)}`,
moduleType: 'js', // NOTE: needs to be set to avoid double `export default` in `?raw&.txt`s
}
}

if (!urlRE.test(id) && !config.assetsInclude(cleanUrl(id))) {
Expand Down Expand Up @@ -207,6 +210,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
? 'no-treeshake'
: false,
meta: config.command === 'build' ? { 'vite:asset': true } : undefined,
moduleType: 'js', // NOTE: needs to be set to avoid double `export default` in `.txt`s
}
},

Expand Down

0 comments on commit 109dd05

Please sign in to comment.