Skip to content

Is it possible to retain browserify's deduping functionality? #33

@bengourley

Description

@bengourley

Thanks for the great module!

I got caught out by this when using a monorepo set up:

// browserify is clever about deduping modules with the same source code,
// but it needs the browser-pack runtime in order to do so.
// we don't have that runtime so this … re-dupes those modules.
if (dedupedRx.test(row.source)) {
var n = row.source.match(dedupedRx)[1]
var dedup = rows.filter(function (other) {
return String(other.id) === n
})[0]
row.source = dedup.source
}

Vanilla browserify was able to successfully dedupe because even though the paths were different, the content was the same, but this process discards that and so you end up with n copies of a dependency in a bundle where n is the number of times it exists on your file system.

I'm assuming arguments[4] is the require() function from the module wrapper? Is it possible to figure out which module it is requiring, put a placeholder to that module in and then reference it by its eventual variable name? e.g. _$validators_14.

Happy to figure out how to PR this but I want to check there wasn't a reason this was avoided in the first place. Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions