1
- import path from 'node:path '
1
+ import { createRequire } from 'node:module '
2
2
import type { Compiler , RspackOptions , RspackPluginInstance } from '@rspack/core'
3
3
import * as rspackCore from '@rspack/core'
4
4
import color from 'picocolors'
5
5
import isCore from 'is-core-module'
6
- import { packageDir , vfs } from './utils'
6
+ import { vfs } from './utils'
7
+
8
+ const require = createRequire ( import . meta. url )
7
9
8
10
export interface CompilerOptions {
9
11
cwd : string
@@ -23,8 +25,14 @@ export function createCompiler(
23
25
24
26
async function handler ( err : Error | null , stats ?: rspackCore . Stats ) {
25
27
const name = '[rspack:mock]'
26
- const logError = stats ?. compilation . getLogger ( name ) . error
27
- || ( ( ...args : string [ ] ) => console . error ( color . red ( name ) , ...args ) )
28
+ const logError = ( ...args : any [ ] ) => {
29
+ if ( stats ) {
30
+ stats . compilation . getLogger ( name ) . error ( ...args )
31
+ }
32
+ else {
33
+ console . error ( color . red ( name ) , ...args )
34
+ }
35
+ }
28
36
29
37
if ( err ) {
30
38
logError ( err . stack || err )
@@ -121,7 +129,7 @@ function resolveRspackOptions({
121
129
rules : [
122
130
{
123
131
test : / \. j s o n 5 ? $ / ,
124
- loader : path . join ( packageDir , ' json5-loader.cjs ') ,
132
+ loader : require . resolve ( '# json5-loader') ,
125
133
type : 'javascript/auto' ,
126
134
} ,
127
135
{
0 commit comments