Skip to content

Commit e2e1f11

Browse files
committed
chore: align require polyfill implementation with the rolldown docs
1 parent 0d8fda0 commit e2e1f11

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as vue from 'vue'
22
import slash3 from 'slash3'
3-
globalThis.require = (dep) => {
4-
if (dep === 'vue') return vue
5-
if (dep === 'slash3') return slash3
6-
throw new Error(`Cannot require "${dep}"`)
3+
4+
export default (id) => {
5+
if (id === 'vue') return vue
6+
if (id === 'slash3') return slash3
7+
throw new Error(`Cannot require "${id}"`)
78
}

playground/external/vite.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs/promises'
2+
import path from 'node:path'
23
import { defineConfig } from 'vite'
34

45
const npmDirectServeConfig = {
@@ -29,6 +30,9 @@ export default defineConfig({
2930
minify: false,
3031
rollupOptions: {
3132
external: ['vue', 'slash3', 'slash5'],
33+
inject: {
34+
require: path.resolve(__dirname, 'src/require-polyfill.js'),
35+
},
3236
},
3337
commonjsOptions: {
3438
esmExternals: ['vue', 'slash5'],

0 commit comments

Comments
 (0)