Skip to content

flegall/haste-map-webpack-resolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status npm version

haste-map-webpack-resolver

A webpack resolver plugin using facebook's haste map.

In CommonJS all require() calls to internal modules are using relative paths.

This can be a pain in mono-repositories:

  • referencing a module requires some relative path computation (very often trial and error).
  • when moving files to different folders, most require() calls have to be updated.

Facebook's Haste map can be useful for that, each module is assigned a unique name using the @providesModule annotation and can be required() using its name.

Since Jest, Flow & React Native are already supporting it, having a webpack resolver is the last thing you need to use it on node.js and on web bundles.

Some resources on it :

This implementation is based on jest-haste-map, the haste map implementation used by Jest runner.

Usage in webpack 1

Add the following code to your webpack configuration file:

var HasteMapWebPackResolver = require('haste-map-webpack-resolver');
var hasteMapWebPackResolver = new HasteMapWebPackResolver({
    rootPath: path.resolve(__dirname, '.'),
});

    ....
    // Within the configuration object:
    plugins: [
        new ProgressBarPlugin(hasteMapWebPackResolver),
        new webpack.ResolverPlugin([hasteMapWebPackResolver.resolver]),
    ],

I've written a fully working webpack 1 demo

Beware this configuration is only valid for haste-map-webpack-resolver 2.x: in order to handle #2 I had to break the configuration of 1.x. If you're still using 1.x, please READ the configuration from here : https://github.com/flegall/haste-map-webpack-resolver/blob/v1.0.8/README.md

Usage in webpack 2

Add the following code to your webpack configuration file:

var HasteMapWebPackResolver = require('haste-map-webpack-resolver');
var hasteMapWebPackResolver = new HasteMapWebPackResolver({
    rootPath: path.resolve(__dirname, '.'),
});

    ....
    // Within the configuration object:
    resolve: {
        plugins: [hasteMapWebPackResolver.resolver],
    },
    plugins: [
        hasteMapWebPackResolver,
    ],

I've written a fully working webpack 2 demo

Beware this configuration is only valid for haste-map-webpack-resolver 2.x: in order to handle #2 I had to break the configuration of 1.x. If you're still using 1.x, please READ the configuration from here : https://github.com/flegall/haste-map-webpack-resolver/blob/v1.0.8/README.md

About

A webpack resolver plugin using facebook's haste-map

Resources

License

Stars

Watchers

Forks

Packages

No packages published