fix(webpack,rspack): incorrect assumption about the current working directory in webpack and rspack (#374)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
This commit is contained in:
NullVoxPopuli 2024-03-29 06:37:40 -04:00 committed by GitHub
parent f7e427da92
commit b0ec0e02ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

@ -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<UserOptions = Record<string, never>>(
factory: UnpluginFactory<UserOptions>,
): UnpluginInstance<UserOptions>['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

View File

@ -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<UserOptions = Record<string, never>>(
factory: UnpluginFactory<UserOptions>,
): UnpluginInstance<UserOptions>['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