0

I have written an es6 library that compiles to produce the following:

// All the library code, then...

export { default as Campaign } from './modules/campaign.js';
export { default as Triggers } from './modules/triggers.js';
export { default as Asset }    from './modules/asset.js';
export { default as AssetSet } from './modules/assetSet.js';

I am then trying to import only Triggers from the library in another project

import { Triggers } from '../../my-library/lib/library.es.js';

When I inspect the bundle it contains all the code for every module exported from my library, rather than just the code from Triggers. I understood that treeshaking would allow me to import just the Triggers code. What am I doing wrong?

My library does not export a default, it only exports the named exports I have written above.

Edit - campaign.js imports asset.js so I would expect to get both when I import Campaign, however Triggers does not reference anything else.

punkrockbuddyholly
  • 9,675
  • 7
  • 36
  • 69
  • What exactly is "*All the library code*"? – Bergi Nov 12 '17 at 14:57
  • Where are you running Rollup, on the library alone or on the other project that imports the library? Also what exactly do you mean "*library that compiles to produce the following*"? – Bergi Nov 12 '17 at 14:58
  • @Bergi I'm using Rollup to build the library then importing the bundled library into another project and using Rollup to bundle that project. The whole library is being included when I'm trying to just include one module. – punkrockbuddyholly Nov 14 '17 at 16:39
  • @Bergi "_all the library code_" is the entire bundle produced by Rollup when I bundle my library. The only export statements in the file are the ones I have included above and they are the last thing in the file. I expected to be able to import individual modules from this individual exports. – punkrockbuddyholly Nov 14 '17 at 16:51
  • I think you should try not to bundle the library but include a raw version (with the individual modules) in the project, so that the project's Rollup process can select the used modules appropriately. – Bergi Nov 14 '17 at 18:31

0 Answers0