Search code examples
javascriptnpmbowerbrowserifybrowserify-shim

Alias a npm module with browserify shim


I'm moving from requirejs to browserify.

I have a dependency for masonry.

That was proving a little difficult (more on that here), to shim using the bower version.

So I just installed it with npm which installs it as masonry-layout.

My question is: How can I shim the named import of a npm modules with thlorenz/browserify-shim? So I don't have to change every reference in my code from masonry to masonry-layout.


Solution

  • I don't think that's the right use case for browserify-shim. Here are a few ideas:

    • You might be able to accomplish what you want using the browser field in package.json. E.g.:

      "browser": {
        "masonry": "masonry-layout"
      }
      
    • If you don't care about being able to install the masonry package as a dependency of the same project and you have symlinks you could symlink node_modules/masonry to node_modules/masonry-layout.

    • You could try my pathmodify browserify plugin.