steal-tools icon indicating copy to clipboard operation
steal-tools copied to clipboard

sideBundle not working with treeshaking

Open pYr0x opened this issue 6 years ago • 3 comments

see this demo app https://github.com/pYr0x/sidebundle

if treeshaking is off, vendor gets bundles out if true, vendor is not bundled

pYr0x avatar Jul 24 '18 19:07 pYr0x

This one might be a little tricky, we have multiple levels of side-effectual modules. I want to avoid preventing rollup from doing its dead code eliminate by having a blanket rule of keeping code when there are no side-effects just it is imported like import "foo"; but this might require that. Still investigating.

matthewp avatar Jul 25 '18 13:07 matthewp

So, what's happening in this case is that the dependencies defined in cc/vendor:

import "popper.js";
import "bootstrap/js/src/dropdown";

Get promoted to to cc/main during tree-shaking:

/*[email protected]#main*/
define('[email protected]#main', [
    '[email protected]#dist/umd/popper',
    '[email protected]#js/src/dropdown',
    '[email protected]#dist/jquery',
    '[email protected]#js/src/util'
], function () {
    'use strict';
});

This is an internal decision to rollup, which we can't really control. Even if we could I'm not sure that we should, just for this use case. Promoting dependencies to parent modules is good in most situations as it means the removal of a module (cc/vendor in this case).

Unfortunately this doesn't play well with the sideBundle feature. So I'm not sure what to do about this. sideBundle's sort of a weird feature, it lets you control how splitting works and that's not something steal-tools ever really did before.

matthewp avatar Jul 26 '18 17:07 matthewp

the actual intention was to create a module that hardly ever changes. this code can be cached very well. any other ideas how to make this work?

pYr0x avatar Jul 26 '18 18:07 pYr0x