Closed Jinjiang closed 9 years ago
This is on purpose and it happens here https://github.com/substack/node-browserify/blob/f9c2561/index.js#L640-L662.
There are two kinds of duplications:
module.exports = {};
. That code can exist in say configA.js
and configB.js
. Duduping is a space saving optimization only. If browserify didn't run the code twice, then it'd be the same as if you'd only required one of the files - clearly breaking things.npm dedupe
. npm will consolidate semver compatible versions of deps. So when two different modules require the same dep, they get the exact same file path.get it! Thx
For example, when both
A
andB
requireX
, the code inX
will be executed twice although the bundle doesn't include the code twice. That's not very convenient in browser ifX
need same config or data for bothA
andB
. This situation is very common for me.I found that the module with same content will be bundled as
{"dup": firstAppearedModuleNumber}
. So I suppose we cound just change these lines below in prelude.jsinto:
But I'm not sure that works fine.
Thx