Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
fix: add globalThis. before helper on server
  • Loading branch information
danielroe committed Mar 13, 2024
commit cb1e10038da074e6f0f720a0b0bbfcc3b79c34fb
5 changes: 3 additions & 2 deletions packages/vite/src/plugins/public-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export const VitePublicDirsPlugin = createUnplugin(() => {
vite: {
load: {
enforce: 'pre',
handler (id) {
handler (id, options) {
if (id.startsWith(PREFIX)) {
return `export default __publicAssetsURL(${JSON.stringify(decodeURIComponent(id.slice(PREFIX.length)))})`
const helper = !options?.ssr || nitro.options.imports !== false ? '' : 'globalThis.'
return `export default ${helper}__publicAssetsURL(${JSON.stringify(decodeURIComponent(id.slice(PREFIX.length)))})`
}
}
},
Expand Down