-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for webpack resolution of modules. #382
Comments
I am also interested in this. I asked a similar question in IRC in Feb: https://botbot.me/freenode/flowtype/2015-02-10/?msg=31705409&page=2 At the time, @gabelevi mentioned that @jeffmo and @mroch were already talking about how to build it. This seems somewhat related to #101. |
I have a feature that I'm working on (that should be ready fairly soon) that will allow you to specify a config entry that lets you write a search/replace regexp pattern that gets applied to all module names before flow attempts to resolve them. It's mostly geared towards supporting things like module aliases, but depending on how complex your lookup algorithm is compared to the built-in one this might achieve what you want? An example of the feature I'm describing would be that you could write a config entry like: module.name_mapper="(.*)", "/some/path/to/where/my/modules/are/\1" This would match all module names and rewrite them to an absolute path somewhere that contains all of your modules. You'll be able to specify multiple of these entries in order to write up different rewrites for different patterns. Would this do what you need by chance? |
What is the behavior if a module name is matched by multiple entries? |
There are a couple of options for how it could work, but at the moment it seems to me that the least surprising would be that the first one that matches (in order of specification) wins. Thoughts? |
My preference would be that the first one that matches that can actually resolve the file wins. That would allow you to have global defaults with reasonable fallbacks. It would also more closely match the strategy that webpack uses which could help for familiarity and adoption. |
Sorry I'm late in replying, but this sounds like this would work swimmingly! +1 to first match that resolves a file wins. |
Ok, I'll take a wack at first-to-match-and-stat. I'm slightly unsure about stating the fs so often (read: perf for big projects), but I might be able to make it work. Thanks for the feedback, this was helpful! |
I just landed this config option yesterday and summarized how it works over toward the end of the following issue. Thanks for the report! |
@jeffmo would this solve my use case for the webpack resolve path? If I use
|
@AdamBrodzinski Yes, it will help, take a look here. |
@kompot Thanks you're the best! working great now 😄 |
For everyone looking at this issue in 2016, I solved this by adding these lines to my
The relevant part of my webpack config is: resolve: {
modules: ["src", "node_modules"]
} |
@dlindenkreuz what did you do exactly? Problem remains for me. E.g. for |
@MoeSattler The important part is that Are you on a recent flow version (>= 0.18.1)? Sometimes, the locally installed flow version in |
@MoeSattler Did you manage to set it up? |
Note that this solutions no longer works in Flow 0.57. In Flow 0.57 they introduced an optimization to,
Because the trick above made Flow think your app modules were another source of node_modules, A working alternative is to explicitly define This script generates the directives you need in [options] of your |
Hmmm... the solution above seemed to work fine for me in flow@0.66.0 |
@kentcdodds I can't get this to work in in
in
I'm trying to do something like |
@JohnDDuncanIII Do you use monorepo? |
When I tried to get Flow working in our project last week, I was saddened that it wouldn't work because of the custom resolution we're using via webpack's
modulesDirectories
.You can read more about our folder structure here: https://gist.github.com/ryanflorence/daafb1e3cb8ad740b346#shared-module-resolution
And webpack's
modulesDirectories
here: http://webpack.github.io/docs/resolving.html#resolving-a-module-pathIs there any chance that Flow will support this?
The text was updated successfully, but these errors were encountered: