simpla icon indicating copy to clipboard operation
simpla copied to clipboard

Create ES module build

Open bedeoverend opened this issue 7 years ago • 4 comments

Currently the module field on package.json points to src/simpla.js but really it should point to a separate build, that's been transpiled, but not bundled. This means that whatever module bundling system consumers are using will still be used, but it won't need to be transpiled. As it currently stands, users can come up against this bug but more generally it'll require them to transpile our source, not just bundle it.

An interim measure would be to change where module points to - just the transpiled, bundled simpla.js in root. The main reason behind giving users an ES module target is so they can tree shake, but as we only have one default export, Simpla, this is pretty redundant.

bedeoverend avatar Oct 04 '17 22:10 bedeoverend

Note: anyone currently facing this problem can get around it by importing simpla.js directly, e.g. use this snippet in your code:

import Simpla from 'simpla/simpla.js'

window.Simpla = Simpla;

this bypasses the default module entry point your bundler might be using.

bedeoverend avatar Oct 04 '17 22:10 bedeoverend

Simpla v3 no longer points to a borked ES build as the main, but now there's no way to import an ES6 build for module-aware bundlers. So this is now a minor enhancement rather than a minor bug.

madeleineostoja avatar Oct 18 '17 22:10 madeleineostoja

As per mentioned in #86, I think we should have ES and UMD builds for each part of Simpla, so that will be:

  • Simpla
  • Simpla Adapters
  • Simpla Mixins (currently just for adding in element stuff)

For UMD builds that'll mean following a naming convention to add to the global namespace e.g. Simpla.X or SimplaX the former being better IMO as it restricts global pollution to just the 1 Simpla

bedeoverend avatar Dec 22 '17 06:12 bedeoverend

Only problem with Simpla.X is ensuring nothing clobbers each other, so you don't have to depend on loading order. Eg: If Simpla.[SomeExternalThing] loads before Simpla core lib.

madeleineostoja avatar Dec 22 '17 06:12 madeleineostoja