Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add dist-custom-elements-bundle output #371

Merged
merged 7 commits into from
May 28, 2021

Conversation

acstll
Copy link
Collaborator

@acstll acstll commented May 28, 2021

@acstll acstll requested a review from eeegor as a code owner May 28, 2021 08:19
@acstll
Copy link
Collaborator Author

acstll commented May 28, 2021

@nowseemee @eeegor 👀

Also, proposal for "export" keys in package.json:

{
  "main": "dist/index.cjs.js",
  "module": "dist/custom-elements/index.js",
  "unpkg": "dist/scale-components/scale-components.esm.js",
}

Consumers will be doing one of these

Stencil lazy-loading via bundler

import { defineCustomElements } from '@telekom/scale-components/loader'
defineCustomElements()

Manual loading ("custom elements" output) via bundler

import { defineCustomElements } from '@telekom/scale-components/dist/custom-elements'
defineCustomElements() // loads everything! almost 1 MB

Stencil lazy-loading via script tag (CDN)

<!-- https://unpkg.com/@telekom/scale-components -->
<script type="module" src="https://unpkg.com/@telekom/[email protected]/dist/scale-components/scale-components.esm.js"></script>

Except for the CDN option ("unpkg" key), these keys in package.json are not relevant since all imports are pointing to some explicit-ish path already.

Both Webpack and Rollup (as mainstream bundlers) support the "module" key. If we set "module" to point to the "custom elements" output, one could do this, which actually ends up making sense:

import { ScaleButton, ScaleCard } from '@telekom/scale-components'

customElements.define('scale-button', ScaleButton)
customElements.define('scale-card', ScaleCard)

Final thoughts

  • "main" shouldn't be used for ESM, so I kept it as-is.
  • "jsnext:main" is deprecated, superseded by "module".
  • I believe "es2015" and "es2017" are Angular stuff, and they point by default to those "empty" index files. I say it's OK to just remove them.

Ref: https://2ality.com/2017/04/setting-up-multi-platform-packages.html

@nowseemee nowseemee merged commit 2d68e3f into main May 28, 2021
@nowseemee nowseemee deleted the feat/custom-elements-output branch May 28, 2021 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants