-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Generate CommonJS and ESM versions of JSCookie along with the UMD version. #666
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
Conversation
In the meantime I started contemplating - for v3 - to drop support for umd modules altogether: We shouldn’t even need CommonJS modules, given the lib isn’t supposed to and will just not work in a node environment. To make this explicit, we have chosen to use the Didn’t think through all the implications of dropping support for cjs yet, certainly it would require ES modules aware bundlers, which I‘m fine for v3. For everything else there would always be v2. |
I think I'd agree on dropping UMD. AMD/RequireJS seems thoroughly dead and probably not worth serving anymore. I do very much disagree on CommonJS. Native ESM module are still in its infancy in many ways. I think it's premature to abandon CommonJS. For example, we had to disable loading ESMs in Webpack because some packages released ESM modules incompatible with the CommonJS modules in the same package which broke either the web build or the Node.js process. Rollup makes it pretty painless to support both and while the number of special case |
So how could a solution look like when dropping support for amd, i.e. umd? We'd have to start providing an iife variant to be used for users not using a bundler (realistic?) and in order to solve #646. Ideally I'm thinking we'd have three variants (iife -> dist/js.cookie.js, esm -> dist/js.cookie.mjs, cmd -> dist/js.cookie.cjs):
(or |
Hmmm, no longer building a umd variant we'd loose |
I'm so confused: #646 (comment) |
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.
LGTM!
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.
Going to merge..
Thanks @realityking 😍 |
@realityking Let‘s say I need to add another iife variant for dist, is there a predefined/recommended setup for package.json? (Needed to close #646) |
Thanks for merging! I don't fully understand your question. What variant are you trying to add? |
We can try this again without breaking jsdelivr 😬 |
I didn’t realize people were so frequently deep linking to a specific build file and don’t pin to specific versions. How annoying (and what an anti pattern when packages can declare which files are to be used for jsdeliver). Two options:
Just kidding about 2. I’ll make a PR for approach 1 this weekend. |
Unfortunately we (the maintainers) created this problem ourselves, by advertising the deep link in the readme: dd1699f Despite prominent note (never prominent enough) I believe many developers are quickly copy&pasting the link from the readme in master, ending up with a release candidate. 💥 I have removed the example altogether now, you get more convenient copy&paste links on jsdelivr anyway. |
Thanks for creating another PR. I've been thinking about the support for older Node.js versions (the // make webpack skip package.json “browser” field
module.exports = {
resolve: {
mainFields: ['module', 'main']
}
} EDIT: Thought: maybe by now Webpack looks for |
This is quite complex makes sure every environments gets the best possible module:
The use of
browser
in the old package.json is problematic as many bundles, including webpack, will by default prefer it overmodule
. In that case the user ends up with an already minified UMD. The UMD is much worse, size wise, than the CommonJS version. Minified dependencies are also bad for debuging.