Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Bundling a reusable library #383

Closed
nukefusion opened this issue Nov 2, 2015 · 3 comments
Closed

Bundling a reusable library #383

nukefusion opened this issue Nov 2, 2015 · 3 comments

Comments

@nukefusion
Copy link

I'm having a real hard time understanding how to package a simple library that I can reuse with jspm. How do I bundle a reusable library whilst only exposing the modules I want, without module ID clashes?

I have an entry point file, index.js:

export { Class1 } from "./Classes/Class1";

When I build it I end up with:

System.register("Classes/Class2.js", [], function(exports_1) {
});

System.register("Classes/Class1.js", ["Classes/Class2.js"], function(exports_1) {
});

System.register("Index.js", ["Classes/Class1.js"], function(exports_1) {
});

It seems to me that anyone could require class2, even though it's just a dependency of class1 and not exposed via my entry point module. What I really want in terms of output is a single module that just exports Class1.

Also, how do I prefix these module paths with some sort of unique package ID? What if another 3rd party package defines Classes/Class1.js

@guybedford
Copy link
Member

Try using jspm bundle-sfx index.js --format cjs for example for something you can publish to npm.

@nukefusion
Copy link
Author

Thanks Guy, I think I must be misunderstanding something. That does give me a single module and desirably encapsulates my private modules, however it also adds 450-odd lines of module resolution logic in an IIFE at the start of the output which seems superfluous for my needs as I will be using jspm/systemjs to import this module into other projects anyway.

If I create many reusable libraries in this way wouldn't that same logic get injected at the start of each library? If I'm using systemjs to import all of these libraries into another project doesn't this approach mean an awful lot of bloat?

@guybedford
Copy link
Member

@nukefusion yes there is some boilerplate, which is necessary to handle the interaction between CommonJS and ES6 circular references. The focus here is then on specific optimizations say if the whole tree is ES6 then we want to use rollup, as in #205.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants