-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
What is commonjs2 ? #1114
Comments
CommonJs spec defines only
|
So ... the replacement of module.exports = function(){}; instead of simply adding stuff to the exports.a = 'a';
exports.b = 'b;' is not in the "initial" commonjs spec ? nodejs started it and everybody followed ? |
@Sinewyk Yeah, pretty much. See https://nodejs.org/docs/latest/api/modules.html for reference. |
Are there other commonjs implementations that do not use |
As described in the document, Although the output of this two build( I have a simple module:
I build this module as commonjs and commonjs2. Then, in another project, I try to import both modules, then I found
So it seems we should build the module as |
I'm also curious. As @vamsiampolu asked, is there a real use case for |
Note, if you you use an external that starts with "@" and you're webpacking for the server you need to use commonjs2 per https://stackoverflow.com/questions/58105364/add-dependency-to-externals-with-in-the-library-name To make this googleable: |
Here are the commonjs module specs if anyone is interested. I think the relevant parts are: Require
Module Context
Unspecified This specification leaves the following important points of interoperability unspecified:
So in webpack's For practicality, I don't know if anyone actually uses this out in the wild. But you could use this in an old browser with no module system. If you load the bundle with a function require(moduleId) {
return exports[moduleId];
} |
Sorry if that's obvious but it's been eating me for multiple days and even
grep
ing commonjs2 through this repository I couldn't find any obvious information.My google-fu on commonjs2 led me back to #864 ... which was not helpful.
Anyone could explicitely inform me what is commonjs2, the differences with commonjs, and what is the relation with webpack ?
Thanks ...
The text was updated successfully, but these errors were encountered: