Skip to content
2 changes: 1 addition & 1 deletion packages/vite/rolldown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const moduleRunnerConfig = defineConfig({
'@vitejs/devtools/cli-commands',
...Object.keys(pkg.dependencies),
],
plugins: [bundleSizeLimit(54), enableSourceMapsInWatchModePlugin()],
plugins: [bundleSizeLimit(55), enableSourceMapsInWatchModePlugin()],
output: {
...sharedNodeOptions.output,
minify: {
Expand Down
19 changes: 15 additions & 4 deletions packages/vite/src/module-runner/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import * as pathe from 'pathe'
import { isWindows } from '../shared/utils'

export const decodeBase64: typeof atob =
typeof atob !== 'undefined'
? atob
: (str: string) => Buffer.from(str, 'base64').toString('utf-8')
export const decodeBase64: (base64: string) => string =
typeof Buffer === 'function' && typeof Buffer.from === 'function'
? (str: string) => Buffer.from(str, 'base64').toString('utf-8')
: atou

function atou(str: string): string {
const binary = atob(str)

if (typeof TextDecoder !== 'undefined') {
const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0))
return new TextDecoder().decode(bytes)
}

return decodeURIComponent(escape(binary))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it’s deprecated. I used TextDecoder for modern environments, and escape as a fallback for older ones.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be a bit slower in my experience. I think there’s more possible here.

Saw your change. Would hoist the textdecoder outside of the function to not reinstantiate all the time.

don’t know if this this function is used a lot in vite. If it’s the case I would probably try to optimize via conditional exports for each runtimes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied the feedback here
9e7202b

}

const CHAR_FORWARD_SLASH = 47
const CHAR_BACKWARD_SLASH = 92
Expand Down