mirror of
https://github.com/unjs/unplugin.git
synced 2026-01-25 16:07:28 +00:00
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:
parent
f7e427da92
commit
b0ec0e02ef
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user