2.0.1 • Published 7 years ago

haste-map-webpack-resolver-demo-webpack2 v2.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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 https://github.com/flegall/haste-map-webpack-resolver/issues/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 https://github.com/flegall/haste-map-webpack-resolver/issues/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

2.0.1

7 years ago

2.0.0

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.1

7 years ago