Comments (4)
Can you create small github repo and provide structure, I need to undestand strcuture and how you are importing this in code, thank you
from enhanced-resolve.
Hey @alexander-akait thanks for responding 🙏🏽,
Here's a minimal reproducible example: https://github.com/Galcarmi/WebpackResolvingIssue
I added a detailed readme file
edit: oops, forgot to add the dist folders, fixed it now in the example
from enhanced-resolve.
@Galcarmi After looking at your code I want to say - your structure is not consistent, top level packages have one logic, inner packages have another, anyway there is an example how you can solve it:
class CustomResolverPlugin {
_isAbsoluteOrRelativePath(request) {
return request.startsWith("/") || request.startsWith("./") || request.startsWith("..");
}
apply(resolver) {
const source = resolver.ensureHook("raw-module");
const target = resolver.ensureHook("undescribed-resolve-in-package");
resolver
.getHook(source)
.tapAsync("NpmResolverPlugin", (resolveRequest, resolveContext, callback) => {
const { request } = resolveRequest;
if (this._isAbsoluteOrRelativePath(request)) {
callback();
return;
}
const packageMatch = /^(@[^/]+\/)?[^/]+/.exec(request);
if (!packageMatch) return callback();
const packageName = packageMatch[0];
const innerInternalRequest = request.slice(packageName.length);
const innerRequest = innerInternalRequest.length === 0 ? `.${innerInternalRequest}` : ".";
try {
const modulePath = path.join(__dirname, 'external_modules', 'current_version_start', packageName, 'current_version_end', packageName, innerInternalRequest);
const obj = {
...resolveRequest,
path: modulePath,
fullySpecified: request.fullySpecified && innerRequest !== ".",
request: innerRequest,
module: false
};
resolver.doResolve(target, obj, null, resolveContext, callback);
} catch {
callback();
}
});
}
}
Note - it is just an example, some things are missing - you need to use this logic https://github.com/webpack/enhanced-resolve/blob/main/lib/ModulesInHierarchicalDirectoriesPlugin.js#L49 and check is it directory, if not - add missing dependecies, otherwise in the watch mode if you add a new package, watcher will not triggered
from enhanced-resolve.
@alexander-akait thanks 🙏🏽🙏🏽🙏🏽 i'll try it
from enhanced-resolve.
Related Issues (20)
- CachedInputFileSystem OOM when duration is infinity HOT 5
- signature of method `stat` in interface `FileSystem` mismatches. HOT 2
- bug: exports map key with star in the middle doesn't work HOT 1
- is this possible with webpack AliasPlugin to automatically switch to a different alias when original file is deleted? HOT 7
- can't resolve exports pattern startsWith wildcards HOT 1
- Use of `extensionAlias` fails resolution of subpath exports in `exports` fields HOT 2
- `exports.types` after `exports.default` HOT 5
- Hooks do not fire events from CSS/SCSS imports HOT 6
- AliasPlugin crash when file is deleted or rename (have to restart to make it work)
- Seeing "Error: No file content" for different package.json files when webpack rebuilds HOT 1
- ESM: Resolving to the wrong package with `exports` and nested same package but different versions HOT 3
- ESM: package.exports array target not conforming to the ESM specification HOT 10
- Add ability to handle win32 relative paths HOT 4
- [Feature Request]: Support resolve the modules with hard-links HOT 4
- lstat error when requiring virtual modules HOT 1
- Can i use withOptions Api ? HOT 1
- File Extension Substitution for TypeScript Support HOT 18
- pathUtils | joinCache memory leak HOT 6
- Question Regarding Restriction on "#/" in Imports Field Key HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enhanced-resolve.