Skip to content

Commit 1482df7

Browse files
add manual support for ESM in NodeJS (#55)
* manually override module field in package.json and update usage docs for ESM and NodeJS support * grammar and docs refining
1 parent cfabd19 commit 1482df7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ This Web Component is developed with [Stencil](https://stenciljs.com).
6464

6565
The [Stencil documentation](https://stenciljs.com/docs/overview) provide examples of Javascript and framework integration for [Angular](https://stenciljs.com/docs/angular), [React](https://stenciljs.com/docs/react), [Vue](https://stenciljs.com/docs/vue) and [Ember](https://stenciljs.com/docs/ember).
6666

67+
### NodeJS
68+
69+
Due to an [open issue in Stencil regarding ESM entry points](https://github.com/ionic-team/stencil/issues/2826), ESM resolution support in NodeJS for this package has been manually fixed by overriding the `module` field in _package.json_. As long as your dev server / bundler supports the `module` field, you should be able to `import` the component like this:
70+
```js
71+
import 'web-social-share';
72+
```
73+
74+
> _Note: as noted in the linked issue, one caveat is that this entry file uses template literals inside dynamic imports (e.g. `import(${x})`) so make sure this syntax is also supported by your environment. For example, Rollup has [**@rollup/plugin-dynamic-import-vars**](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars).
75+
6776
## Getting Started
6877

6978
The Web Social Share Component can be use like following:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "8.0.0",
44
"description": "A Web Component to share urls and text on social networks",
55
"main": "dist/index.cjs.js",
6-
"module": "dist/index.js",
6+
"module": "dist/websocialshare/websocialshare.esm.js",
77
"es2015": "dist/esm/index.js",
88
"es2017": "dist/esm/index.js",
99
"jsnext:main": "dist/esm/index.js",

0 commit comments

Comments
 (0)