thlorenz / browserify-shim

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

shimming linkurious #215

Closed ekkis closed 8 years ago

ekkis commented 8 years ago

I'm trying to use the linkurious library (a sigma fork), which provides a "main": "dist/sigma.require.js" (in the package.json). this allows me to do:

var sigma = require('linkurious');

however, the plugins are not included so I have to require them separately. the problem is that the plugins rely on the sigma variable being available in the global scope. so I've shimmed things as follows (from the package.json):

  "browser": {
    "sigma": "./node_modules/linkurious/dist/sigma.js",
    "linkurious/plugins": "./node_modules/linkurious/dist/plugins.js"
  },  
  "browserify-shim": {
    "sigma": {"exports": "sigma"},
    "linkurious/plugins": { "depends": [ "sigma" ]  }   
  },  
  "browserify": {
    "transform": [ "browserify-shim" ]   
  }, 

which, when run in a browser doesn't generate errors during inclusion of the plugins (which I gather means the global variable is available) but references to the plugins fail (as if they failed to attach themselves, or attached themselves to a non-global variable).

I've attached a little project to this issue with the minimal required code to demonstrate the problem in the hopes that someone else can replicate/figure out. unpack, type npm start and run a browser against http://localhost:8002/ to see the issue.

thanks in advance,

ekkis

sigma.zip

- edit I -

forgot to mention, before running: npm install

bendrucker commented 8 years ago

Are you running browserify-shim as a global transform?

ekkis commented 8 years ago

thanks for the quick reply. I'm not sure I understand. the "browserify": { "transform": ... } specifies that? please elaborate?

bendrucker commented 8 years ago

https://github.com/thlorenz/browserify-shim/issues/191

ekkis commented 8 years ago

ah. I think I understand your question now. I use grunt-browserify with the following definition:

    grunt.initConfig({
        browserify: {
            libs: { files: { 'inc.js': ['index.js'] }   },
        }
    });

and somewhere down below:

grunt.registerTask('build', [ 'browserify' ]);

bendrucker commented 8 years ago

Alright, I'm going to go ahead and close this out. Seems like you just need to figure out how to run a global transform in your setup.

ekkis commented 8 years ago

I need a global transform (I'm not sure I know what that is)? is there documentation you could point me to?

bendrucker commented 8 years ago

http://stackoverflow.com/questions/35228943/allow-global-transforms-with-grunt-browserify

bendrucker commented 8 years ago

I'll let you take it from here, hope this is helpful

ekkis commented 8 years ago

I read through that article. I had already come across it. but it's a question without an answer. if I need a global transform (not sure I understand quite what it is) then it seems it's just not available. so I cannot browserify this library. is that the answer?

ekkis commented 8 years ago

one other thing I don't understand: if you're suggesting that I need a global transform, why? I only have one module that has a dependency on another. perhaps I've expressed it incorrectly but global transforms are for when you have lots of modules that all need a dependency and you want to specify it in a blanket manner, no?

ekkis commented 8 years ago

hei. it's been pointed out to me on IRC that github isn't meant for usage questions and I should ask on SO. sorry about that. I didn't realise. I'll post on SO, and thanks for the help