11import resolve from 'browser-resolve' ;
22import hashsum from 'hash-sum' ;
3- import { dirname } from 'path' ;
3+ import * as events from 'events' ;
4+ import * as util from 'util' ;
5+ import { dirname , basename } from 'path' ;
46import type FSType from 'fs' ;
57import detectOldBrowser from '@codesandbox/common/lib/detect-old-browser' ;
68import evaluateCode from '../../../loaders/eval' ;
@@ -24,6 +26,14 @@ export default function evaluate(
2426 availablePresets
2527) {
2628 const require = ( requirePath : string ) => {
29+ if ( requirePath === 'events' ) {
30+ return events ;
31+ }
32+
33+ if ( requirePath === 'util' ) {
34+ return util ;
35+ }
36+
2737 if ( requirePath === 'assert' ) {
2838 return ( ) => { } ;
2939 }
@@ -42,12 +52,12 @@ export default function evaluate(
4252 }
4353
4454 if ( requirePath === 'require-from-string' ) {
45- return ( newCode : string ) =>
55+ return ( newCode : string , sourcePath : string ) =>
4656 evaluate (
4757 fs ,
4858 BFSRequire ,
4959 newCode ,
50- '/' ,
60+ sourcePath ,
5161 availablePlugins ,
5262 availablePresets
5363 ) ;
@@ -154,9 +164,15 @@ export default function evaluate(
154164 finalCode = transpiledCode ;
155165 }
156166
157- const exports = evaluateCode ( finalCode , require , cache [ id ] , {
158- VUE_CLI_BABEL_TRANSPILE_MODULES : true ,
159- } ) ;
167+ const exports = evaluateCode (
168+ finalCode ,
169+ require ,
170+ cache [ id ] ,
171+ {
172+ VUE_CLI_BABEL_TRANSPILE_MODULES : true ,
173+ } ,
174+ { __dirname : dirname ( path ) , __filename : basename ( path ) }
175+ ) ;
160176
161177 return exports ;
162178}
0 commit comments