I am trying to build a library in Coffeescript using Browserify, and it looks like both are interacting in a weird way which cause problem,
I'm trying to build a library with submodules, where I can either
lib = require('lib')
lib.submodule.function(...)
or
submodule = require('lib/submodule')
submodule.function(...)
Here is a simple example showing such a library: https://github.com/maelp/browserify-lib
git clone git@github.com:maelp/browserify-lib.git
cd browserify-lib
npm install && gulp
It build fine, however when opening index.html
I have an error when requiring "myLib" (but require('myLib/submodule')
works fine)
Anyone knows what I should change, and whether this is due to a conflict between Coffeescript and Browserify require
function?
In order to expose 'myLib/submodule' I do this in the Gulpfile:
libraryExposes = [
{expose: 'myLib', require: './index.coffee'}
{expose: 'myLib/submodule', require: './submodule'}
]
gulp.task 'default', () ->
...
for item in libraryExposes
bundler.require(item.require, expose: item.expose)
...
and it seems that it replaces the './submodule' by 'myLib/submodule' in the generated library, but then it cannot find './submodule', check http://pastebin.com/EQL2hevy :
line 27: it replaces "./submodule" with "myLib/submodule"
},{"../a":1}],"myLib/submodule":[function(require,module,exports){
... the code of ./submodule
line 45: it cannot find the reference to "./submodule"
},{"./a":1,"./submodule":undefined}]},{},[]);
(note that I would like to be able to use require('./submodule')
in my code because I don't want to have to know in advance what submodules I want to expose when I'm coding)