Duplicate module loading across files with browserify

565 views Asked by At

Assume the following files:

file1.js

var mui = require("material-ui");

module.exports = {//something}

file2.js

var mui = require("material-ui");

module.exports = {//something}

main.js

var file1 = require("./file1");
var file2 = require("./file2");

As you can see I'm loading the material-ui module twice, will this affect the file size of my final build? Should I define a 'global' material-ui object in my main.js file?

I hope my question is clear enough. I use gulp to compile my javascript.

1

There are 1 answers

1
marcel On BEST ANSWER

No, browserify will bundle it once.

Every file will get an own scope and every time, a file requires an other one, browserify will check if the required file already was included.

So it won't affect the file size of your final build.