javascript - How to disable Tree shaking in rollupjs -
i trying bundle several javascript files using rollup.js when do, classes aren't used removed. process called tree shaking , want disable it.
i have found this doesn't seem have effect.
// rollup.config.js let configuration = { output: { format: 'es', }, name: 'namename', input: './main.js', treeshake: false, // <-- disabling tree shaking? }; export default configuration;
i added treeshake: false
configuration, doesn't seem have effect. supposed placed somewhere else?
here files trying roll up.
// base.js export default class base { amethod() { return "hello"; } } // main.js import base './base.js';
so set up, call rollup --config
, produces empty. clearly, tree shaking happening , removing base class though imported it.
so far workaround i've found create instance of class, undesirable.
// main.js import base './base.js'; export default function () { { new base(); } }
my goal use bundled javascript file jscontext. take in javascript string , there, i'd invoke methods needed.
// suppose rollup.js produces file called "product.js" let s = string(contentsoffile: "path/to/product.js") let context = jscontext()! context.evaluatescript(s) context.evaluatescript("var b = new base()") context.evaluatescript("b.amethod()")
but because of tree shaking base class never gets placed in product.js
is there way disable tree shaking?
i've included sample project this.
your entry file — main.js
— needs export classes or other values need accessible outside world:
// main.js import base './base.js'; import subb './subb.js'; import suba './suba.js'; export { base, suba, subb };
Comments
Post a Comment