thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
934 stars 87 forks source link

Doesn't work with paths #211

Closed letmaik closed 8 years ago

letmaik commented 8 years ago

I'm trying to do something like:

  "browserify-shim": {
    "covutils/lib/constants.js": "global:CovUtils.constants"
  }

I'm require'ing certain modules of a package and those modules are exposed in the corresponding browser bundle within a global object. The above however doesn't work with browserify-shim. I don't see "CovUtils.constants" anywhere in the output file. Is this not supported?

bendrucker commented 8 years ago

Correct, it won't work as-is. You're trying to transform the contents of your node_modules directory which means you need to run browserify-shim as a global transform.

browserify -g browserify-shim entry.js

letmaik commented 8 years ago

I tried this in various ways but it still doesn't change anything. I tried the following paths:

    "./node_modules/covutils/lib/constants.js": "global:CovUtils.constants"
    "node_modules/covutils/lib/constants.js": "global:CovUtils.constants"
    "covutils/lib/constants.js": "global:CovUtils.constants"
bendrucker commented 8 years ago

Replaced my original comment when I realized what you were trying to do

letmaik commented 8 years ago

I noticed that and had used your new comment as a base already, running it as a global transform with -g browserify-shim. Any idea?

bendrucker commented 8 years ago

If you send me a working project I can step through in a debugger and see if it's reasonable to make this work or not.

letmaik commented 8 years ago

Sure, just clone https://github.com/Reading-eScience-Centre/covjson-reader and do an npm install && npm run build. In the generated covjson-reader.src.js file I would expect to find CovUtils.constants somewhere since src/constants.js imports 'covutils/lib/constants.js'. You can find the transpiled code under the lib/ folder which is then used for browserify.

bendrucker commented 8 years ago

Global functionality is provided by https://github.com/thlorenz/exposify. It doesn't support path resolution and I'd rather not add it since it massively increases the project's complexity.

letmaik commented 8 years ago

Ok thanks for looking at it. This feature is supported by the JSPM bundler, maybe I can create my bundles with that, although I've never done that for pure npm packages (vs jspm packages).