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

Provide es module source and/or join forces? #38

Open
daKmoR opened this issue Nov 17, 2018 · 4 comments
Open

Provide es module source and/or join forces? #38

daKmoR opened this issue Nov 17, 2018 · 4 comments

Comments

@daKmoR
Copy link

daKmoR commented Nov 17, 2018

hey,

I would like to import this plugin as an es module
so I can do something like this:

import { chaiDom } from 'chai-dom';

window.chai.use(chaiDom);

as an example for a diffrent plugin see https://github.com/open-wc/open-wc/blob/master/packages/testing/register-plugins.js

possible solutions:

  1. convert to es module
    • in file index.js? or src/index.js?
    • possibly also es6
    • rollup config to create an umd module in chai-dom.js (will be full compatible)
    • will require a fast npm run build before publishing
    • I can make a MR if wanted
  2. publish separately as a bundled es module
    • no change from you side
    • separate repo having a depency on chai-dom and using rollup to create an es module version (we already did that for other stuff see https://github.com/bundled-es-modules)
    • not ideal but workable
  3. integrate directly in open-wc monorepo (you wann join the team?)
    • could be a "fork" @open-wc/chai-dom only exposing es module (e.g. to reduce complexity)
    • could be a next major version of chai-dom (only es module to reduce complexity)
    • could be a fully compatible version of chai-dom using rollup (if really needed)

If #7 still holds true just let me know and will move forward with 2) - although for obvious maintainability reasons I would prefer 1) or 3) but just let me know

@nathanboktae
Copy link
Owner

Just drop the brackets. I have no build system now so why should I introduce such complexity for no benefit? No tree shaking would be possible still, and as a testing library, size is not an issue.

import chaiDom from 'chai-dom'
window.chai.use(chaiDom)

@daKmoR
Copy link
Author

daKmoR commented Nov 17, 2018

import chaiDom from 'chai-dom'
window.chai.use(chaiDom)

that only works when using a build tool for the tests right?

if you use this directly in the browser it will fail as chai-dom is an umd module and not a native es module... and browsers can't es import umd modules.

I can totally understand if you do not want to do this - feel free to close the issue.

@nweldev
Copy link

nweldev commented Aug 7, 2019

@nathanboktae I've exactly the same use case as @daKmoR described here: no build tools, I only use ESM in the browser. So, in order to experiment this, I created a small gist and it works just fine.

From my point of view, It would be possible for chai-dom to move to ESM the same way, and then to easily generate AMD and CommonJS using, for example, Babel (ESM to AMD & ESM to CommonJS)

FYI, I tried some workarounds before that (like using @polymer/esm-amd-loader) but failed to make them works.

@nathanboktae
Copy link
Owner

On second thought, yes it'd be nice to join the ES module train. I'll have to break down and have some build tools. Previously with UMD I didn't need to :)

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

No branches or pull requests

3 participants