Skip to content

Pluggable resolvers? #110

@petehunt

Description

@petehunt

Hey webpack team --

I'm currently evaluating webpack as the replacement for our current module loader on Instagram.com.

I see in the docs that you describe your module resolution process: https://github.com/webpack/docs/wiki/resolving but I can't figure out if this is pluggable or not.

EDIT (sokra): http://webpack.github.io/docs/resolving.html

Our client-side codebase is a decent size (20kloc of JS for the app itself, 50kloc with JS dependencies) and I would prefer to not have to refactor all of it to adopt webpack.

First, we originally used RequireJS so we require() everything in the application relative to the root. For example, if a component in lib/ui/Button.js wants to require a component in lib/ui/Whatever.js, the statement we use is require('lib/ui/Whatever') rather than require('./Whatever'). This makes refactoring much easier (a best practice adopted from Facebook's hugely massive codebase).

Second, we integrate deeply with the Facebook codebase which uses an alternate way of resolving modules. A good example of how this works is React (https://github.com/facebook/react/blob/master/src/core/React.js). We put /** @providesModule XYZ */ in a JS file and then we can do require('XYZ') to get it.

Today we do a prebuild step that has to move a bunch of files around on the filesystem, or rewrite all of the requires to the right place.

It would be nice if I could provide a function (moduleID) => pathToFile to webpack that it would use to resolve these paths. Then I could replace basically our entire toolchain with webpack and a few custom loaders/resolvers. Once this is working on Instagram it'd likely find its way to the React project in open-source as well.

I understand that this is somewhat of a one-off request for us, but I do know that Browserify and RequireJS resolve paths differently, so making the resolution strategy pluggable is probably generalizable outside of this use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions