browserify / factor-bundle

factor browser-pack bundles into common shared bundles
Other
400 stars 27 forks source link

Single index/common bundle with separate plugins #91

Closed fis-cz closed 6 years ago

fis-cz commented 6 years ago

Hello,

I would like to ask if it is possible to achieve the following scenario with f-b.

I would like to have

index.js plugin1.js plugin2.js

where index is application itself and includes all common modules for index, plugin1 and plugin2 bundles. plugin1 and plugin2 are bundles I'd like to lazy load later within the application and each of them should contain just modules related to it.

Of course, I can do something like

browserify --debug ./build/index.js ./build/plugin1.js ./build/plugin2.js -p [factor-bundle -o ./temp/index.js -o ./dist/plugin1.js -o ./dist/plugin2.js] -o ./temp/common.js

then merge common.js with index.js using i.e.

cat ./temp/common.js ./temp/index.js > ./dist/index.js

but I'll loose maps in this case.

goto-bus-stop commented 6 years ago

it sounds like you might want split-require. you can use it to lazy load bundles by doing:

var sr = require('split-require')

function loadPlugin1 (callback) { sr('./plugin1', callback) }

then build your app using:

browserify index.js -o dist/index.js -p [ split-require --out dist/ ]
fis-cz commented 6 years ago

Hello,

thanks for response.

looks promising, but I have wrote my own bundler with async runtime components better fitting my needs.

gryphonmyers commented 5 years ago

@goto-bus-stop I am trying to achieve the same thing. I gave split-require a whirl and it seems great, but I'm noticing that if plugin1.js and plugin2.js both require the same dependency, it will be duplicated in both bundles. Is there any way to get split-require to put such shared dependencies into the main (in this case, both "common" and single entry-point) bundle? I see there are instructions for getting split-require working with factor-bundle, but factor-bundle seems to assume you have multiple entry points so I really have no idea which of these tools, or both in tandem is appropriate for the job.