diff --git a/src/rspack/index.ts b/src/rspack/index.ts index a232d4d..0f4e0fb 100644 --- a/src/rspack/index.ts +++ b/src/rspack/index.ts @@ -19,14 +19,16 @@ const LOAD_LOADER = resolve( __DEV__ ? '../../dist/rspack/loaders/load.js' : 'rspack/loaders/load', ) -const VIRTUAL_MODULE_PREFIX = resolve(process.cwd(), '_virtual_') - export function getRspackPlugin>( factory: UnpluginFactory, ): UnpluginInstance['rspack'] { return (userOptions?: UserOptions): RspackPluginInstance => { return { apply(compiler) { + // We need the prefix of virtual modules to be an absolute path so webpack let's us load them (even if it's made up) + // In the loader we strip the made up prefix path again + const VIRTUAL_MODULE_PREFIX = resolve(compiler.options.context ?? process.cwd(), '_virtual_') + const injected = compiler.$unpluginContext || {} compiler.$unpluginContext = injected diff --git a/src/webpack/index.ts b/src/webpack/index.ts index 78ba22a..c78aac3 100644 --- a/src/webpack/index.ts +++ b/src/webpack/index.ts @@ -16,17 +16,16 @@ const LOAD_LOADER = resolve( __dirname, __DEV__ ? '../../dist/webpack/loaders/load' : 'webpack/loaders/load', ) - -// We need the prefix of virtual modules to be an absolute path so webpack let's us load them (even if it's made up) -// In the loader we strip the made up prefix path again -const VIRTUAL_MODULE_PREFIX = resolve(process.cwd(), '_virtual_') - export function getWebpackPlugin>( factory: UnpluginFactory, ): UnpluginInstance['webpack'] { return (userOptions?: UserOptions) => { return { apply(compiler: WebpackCompiler) { + // We need the prefix of virtual modules to be an absolute path so webpack let's us load them (even if it's made up) + // In the loader we strip the made up prefix path again + const VIRTUAL_MODULE_PREFIX = resolve(compiler.options.context ?? process.cwd(), '_virtual_') + const injected = compiler.$unpluginContext || {} compiler.$unpluginContext = injected