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 ES6 Module build #352

Open
jdittrich opened this issue Jun 1, 2020 · 8 comments
Open

Provide ES6 Module build #352

jdittrich opened this issue Jun 1, 2020 · 8 comments

Comments

@jdittrich
Copy link

I would like to use stampit as ES6 module. However, it currently is only compatible with common.js or global variable use (If I understand correctly).

Is it possible to add an ES6 build of stampit?

@koresar
Copy link
Member

koresar commented Jun 2, 2020

Yes. It is possible. Please, guide me through.

Do I need to add "module": "dist/stampit.module.js", to the package.json?
Anything else is needed?

@jdittrich
Copy link
Author

jdittrich commented Jun 2, 2020

Thanks!

Do I need to add "module": "dist/stampit.module.js", to the package.json?
This, too, if I understand it correctly (not an expert on this)

It seems that currently, stampit uses node-compatible common.js-style module.exports or export to a global variable (see code) and an optional build step via uglyify to get a minimized version of the library.
I guess the best way would be writing ES6 style and converting to common.js via rollup (minimal example). But this might be too much of a change so I understand if this is not priority.

@koresar
Copy link
Member

koresar commented Jun 2, 2020

Wow. Your know more than me!

I heard this might be a good option to publish module like stampit https://github.com/developit/microbundle

@koresar
Copy link
Member

koresar commented Jun 2, 2020

We accept PRs 😉
Even half baked PRs 😉

@jdittrich
Copy link
Author

Before I cause a mess there – it seems that the code as been ES6 compatible, but was subsequently changed. This seems to have been part of minification, which I do not fully understand (was this for the code to be small itself or for being better minify-able?).
Another thing that is striking is the use of "var1", "var2"… through the code, introduced in "further minification 7" – why var var1 instead of var properties? (similar changes towards less speaking variable names were also done before, e.g. in "further minification 2")

@koresar
Copy link
Member

koresar commented Jun 4, 2020 via email

@PopGoesTheWza
Copy link
Contributor

Out of curiosity, what are the use cases for ES modules?

One "silly" idea comes to my mind: have the source use ES Module syntax and use TypeScript compiler to compile the CommonJS version.

If there is any other tool chain to transform CommonJS to ESM (or vice versa) I'd gladly give it a look.

@koresar
Copy link
Member

koresar commented Jun 8, 2020

Out of curiosity, what are the use cases for ES modules?

The modern tooling usually works fine with both - ES6 exporting and the CJS. However, they work slightly better with ES6 exporting version.
There is nothing to treeshake in stampit, so that can't be the main reason.

One "silly" idea comes to my mind: have the source use ES Module syntax and use TypeScript compiler to compile the CommonJS version.

That's a good idea. I was thinking about it a lot myself. Can be done with Babel compiler too. Or Rollup. Or the above mentioned microbundle.

If there is any other tool chain to transform CommonJS to ESM (or vice versa) I'd gladly give it a look.

Here is my typical approach.
I copy the the Preact project setup. :)

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