-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: master
Are you sure you want to change the base?
Conversation
output: { | ||
file: pkg.browser.replace(/\.js$/, '.mjs'), |
There was a problem hiding this comment.
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.
cbb8c7d
to
8707b33
Compare
commonjs(), | ||
terser(), | ||
append('module.exports = (JSOX.JSOX = JSOX);'), |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
8707b33
to
526c426
Compare
Frendly ping @d3x0r |
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 withrollup
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 viajsdoc
types.It's a bit painful to contribute on this project because there is no
.editorconfig
orformatter
to be used which is very easy to code with different styles. I would recommend to addprettier
support and tools likelint-staged
to ensure a consistent code style.