Closed ftes closed 3 years ago
That wrench confused me for a second. I though it was some new github feature :-D
There was already some effort in #26 regarding commonjs, but it did not receive any more feedback. (See also: https://github.com/gertqin/vuex-class-modules/tree/feature/commonjs) If the solution is really as simple as this, then I would be fine with it.
I just love my emojis 😉 Yes, I do think it is as simple as this. I tested my change locally. I'm happy to provide an example if you like.
My solution can solve #26. But only if you specifically import from "vuex-class-modules/lib/commonjs" (because, of course, the default import is the es2015 module in package.json:
"main": "lib/index.js"`).
feature/commonjs
1cd45babIt looks like rollup was added. That is not necessary imho. We don't need to bundle the output, just expose it using commonjs
module system. And tsc
can do that out of the box.
Maybe we can reference both the esm build as well as the commonjs build in package.json.
I'm never really sure what to put where.
Perhaps set commonjs in main
and esm in module
?
Also it would be great if you could add a small description in the readme. I know it is getting longer and longer all the time, but it is the main documentation of this library :-)
Perhaps set commonjs in main and esm in module?
I agree. I tried to read up on this quickly and would suggest following this approach (conditional exports are no longer hidden behind a node feature flag): https://2ality.com/2019/10/hybrid-npm-packages.html#option-1-(experimental%2C-needs-conditional-exports)%3A-esm-and-commonjs-are-both-bare-imports
"type": "module",
"main": "commonjs/index.js",
"module": "lib/index.js",
"exports": {
".": {
"require": "./commonjs/index.js",
"default": "./lib/index.js"
}
},
I have update the PR (as mentioned in my previous comment).
I have added a brief description to the readme.
Here is a working example for both the esm
build (used by webpack) as well as the commonjs
build (used by vanilla node v14).
https://github.com/gertqin/vuex-class-modules/commit/33e325750a8801504e058d4e895207709aa190c6
Looks good! Thanks for the contribution. :)