Closed jeron-diovis closed 8 years ago
Can you please set up a project that reproduces this? No task runners please, just a minimal package.json and the two libs.
https://github.com/jeron-diovis/bshim_demo
While preparing this repo I've learned, that adding shim with exports
section for module forces builder to don't pass a module
variable inside, so such module works just as if it was loaded in browser.
Probably, that was my mistake, and using shims for "exporting" isn't a correct usecase.
Still, I will describe my steps here - maybe, there are something more important things I didn't understand yet.
So, on each following step run "npm start" to build an app and then load index.html.
Steps:
require
isn't replaced with __browserify_shim_require__
.require
- while Sightglass is still exported to it's module
.depends
section in rivets shim.
Sightglass is still present in build, but under it's filepath - while rivets tries to load it by alias.
This can be fixed using -r sightglass
option for browserify - it adds an alias and maps filepath to it. But, unexpectedly, rivets now again gets it's module
variable, so everything works like on step 1, with only difference - require
not is replaced with __browserify_shim_require__
. Whether this all makes any sense, I don't understand.That's all. So what I understood:
require
inside module with __browserify_shim_require__
module
variable inside, turning module in "browser mode". This can be overridden with -r
option.What I still don't understand:
depends
section are added to build under their filepaths instead of aliases, defined in config?Were you able to resolve this?
why modules from
depends
section are added to build under their filepaths instead of aliases, defined in config?
This is the last thing I can't understand myself. Such behaviour looks quite strange for me. Besides this, I learned where I was wrong.
You can configure using aliases or paths:
https://github.com/thlorenz/browserify-shim#b-config-inside-packagejson-with-aliases
It's probably a stupid newbie's issue, but I definitely need clarifying.
I'm trying to build project with Rivets library.
Rivets depends on external lib Sightglass like this:
And Sightglass exports itself like this:
In package.json I have:
Running browserify with browserify-shim with only this config works just fine.
require
call in rivets module is replaced with__browserify_shim_require__
, and asightglass
dependency is added to bundle automatically. Everything is put intomodule
, no globals.Then I thought that I need to export rivets to globals:
But after this
sightglass
no more appears in bundle.Ok, probably, if shim is defined for module, it manages this module completely, disabling auto-discovering dependencies. So I need to do it manually now:
After this
sightglass
appears in bundle again - but under it's full file path instead of justsightglass
alias. And nothing works, because module named "sightglass" can't be found.So, to make things finally work, I must either get rid of this shim and export to globals manually in my code with
window.rivets = ...
, or run browserify with-r
option to force it to finally add a module named "sightglass".And now my question is simple - is this all how things supposed to work? Am I doing something wrong, didn't I found some option in manual which will solve my problem - or everything above is just a standard usecase?