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: generate commonjs output from ESM source #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JounQin
Copy link

@JounQin JounQin commented Dec 19, 2023

This is first a POC to see whether will it be accepted.


related #13

In this PR, the only source will changed to be lib/jsox.mjs which is an ESM file.

The commonjs entry lib/jsox.js will be generated with rollup automatically, and I don't see any use of the minified commonjs. If we want to support the browser field, we should generated an umd format output instead, otherwise we should keep to use the ESM source.

Secondly, the types are generated via tsc automatically via jsdoc types.

image image

It's a bit painful to contribute on this project because there is no .editorconfig or formatter to be used which is very easy to code with different styles. I would recommend to add prettier support and tools like lint-staged to ensure a consistent code style.

output: {
file: pkg.browser.replace(/\.js$/, '.mjs'),
Copy link
Author

@JounQin JounQin Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The browser field was lib/jsox/es6.js.gz, I don't think it's working correctly because the codes mean lib/jsox/es6.js.gz will be ESM format actually. If you want to use ESM for browser, we can use default entry.

commonjs(),
terser(),
append('module.exports = (JSOX.JSOX = JSOX);'),
Copy link
Author

@JounQin JounQin Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why the pattern module.exports = JSOX; exports.JSOX = JSOX does not work on Node now. But the hack here is also as easy as possible, and it works as expected.

@@ -16,17 +16,15 @@
"@std/esm": "cjs",
module: "lib/jsox.mjs",
main: "lib/jsox.js",
browser: "lib/jsox.es6.js.gz",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lib/jsox.es6.js.gz file generated by build script is actually an ESM output, we can just use the mjs entry instead.

@JounQin
Copy link
Author

JounQin commented Dec 20, 2023

Frendly ping @d3x0r

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.

1 participant