-
Notifications
You must be signed in to change notification settings - Fork 185
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
fix(build): svelte packaging #1258
Conversation
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.
@benmccann As always, thank you for taking the time. This is a great improvement.
I've built and tested this locally. I no longer encounter the error as described in: metonym/carbon-charts-svelte-examples#1
However, one small runtime error I faced was that the svelte/main entry should still be src/index.js
as the folder is copied over to dist when building for production.
The published assets have the following structure:
I still see the vite SSR errors in the console, but it is non-blocking as the app successfully runs in development:
For the |
It would work to point to either a bundled or unbundled entry point as long as it's ESM. However, there are performance benefits to pointing to a bundled file (sveltejs/kit#2612) and you may get bug reports about slowness if you point at the unbundled version. That's why I pointed to the bundled version instead, so I'd probably lean against changing it to the source version |
Actually, I take it back. It's much better to just distribute the source. Svelte expects uncompiled |
Awesome. One last requested change: # svelte/build.sh
rm -rf dist
+ mkdir dist
- echo "bundling..."
- rollup -c |
good catch. done! |
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.
@benmccann Seems like we're introducing a breaking change by switching the core bundle from umd to cjs.
Why not also offer a umd bundle?
Thanks for taking a look @theiliad! UMD modules try to guess at runtime which module system they're being used in, and then act as that kind of module. The idea is that you can load the file in a plain |
No worries! Yes we do have umd users AFAIK main usually is umd, as bundlers usually look at the module field... @metonym feel free to chime in if you'd like Also found this just searching https://2ality.com/2017/04/setting-up-multi-platform-packages.html |
Yes, that's mostly true. Most bundlers look at things in the following order:
It's quite rare in my experience. What I have seen somewhat frequently though is to list UMD in fields used by CDNs like Putting a UMD package in
Do you know anything else about how they use it? E.g. do they have a build process that includes it via
It's a starting point to understanding this stuff, but I wouldn't rely on it too heavily since it's from 2017. E.g. it doesn't talk about |
Any thoughts about this one? |
@theiliad If users do use the UMD version, would the following be amenable?
|
Yes I think that works. Although I see it a lot, I'm also not a big fan of having UMD be the The reason for that is even say in a react project with some bundlers you could end up (unintentionally) using UMD in dependencies... which I think destroys tree-shaking... So say you're using |
@benmccann are you able to apply these changes? Also, where do you see the names of fields that |
I don't think that we'd want to add a UMD file in the I'm happy to add the UMD file with fields for the CDNs. Here are the main ones I've seen used in other projects:
|
Let's read some more on bundling & package.json as I think the way that they're done has changed in the past 1-2 yrs. Lmk if you encounter anything interesting |
I'm pretty up-to-date and familiar with the bundling stuff. Are there any specific questions I can help answer? Here are some helpful references: |
Thanks Ben. So seems like the default values on most of these use then Module and browser could be our es6-like entrypoints |
The issue is with NodeJS. The only thing it prefers above |
Why would someone use this in NodeJS? |
SvelteKit is isomorphic. It will render all code on the server and the client by default the way the instructions are setup: https://github.com/carbon-design-system/carbon-charts/tree/master/packages/svelte#basic That should not be an issue with most libraries. But if you want to say that it's only supported in the browser then the docs should be updated to recommend only doing something like https://github.com/carbon-design-system/carbon-charts/tree/master/packages/svelte#dynamic-import |
Does svelteKit not offer a way to choose the main field used? |
SvelteKit uses Vite and Vite does provide a way to choose the main field, but in practice that's a pretty useless feature (not just in Vite, but in most bundlers) because it applies to all packages and if you change it then you'll almost certainly break some other package. But perhaps more importantly, Vite isn't heavily involved here and that option wouldn't affect this code path. Vite is not bundling this code and is just asking NodeJS to run it. It's the node package resolution algorithms that get invoked here that cause the |
I've reverted the change to the core package for now. I discovered another issue with the way it's packaged and I think it's better to address separately. And in the meantime I'd love to at least get the change to the Svelte package checked in since it's less controversial 😄 |
@metonym what are you thinking here? As mentioned earlier I'm not a big fan of UMD being the I don't particularly mind switching out our |
I've been doing some more testing and am actually not sure that it'd fix it. Or at least that change alone might not fix it. I'd feel better about merging this with just the Svelte changes actually and coming back to the core changes after I've had more time to test. It's really hard for me to test this because I can't get the library to build. I ran into another issue while trying to use npm that perhaps you could fix as well? #1277 I'm unable to send a PR with the fix for that one since I can't get yarn to work to update the |
Last time I looked into this, the |
Is there some way I can build the core package that doesn't involve installing the dependencies for the angular package? |
Yes, that's the same as now. This cleans things up a bit, but doesn't solve all issues. I'd like to do the rest in a follow-up if that's okay since the discussion on this PR has already gotten quite long. |
@benmccann Fine by me 👍 The update to the Svelte chart wrappers is an improvement though; it removes this vite warning:
|
I finally got this package building. I had to downgrade to an older version of Node. So I was now able to track down the problem and left a comment on the issue explaining the problem: metonym/carbon-charts-svelte-examples#1 (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.
mostly going off of @metonym 's approval here since it's svelte
Thanks @benmccann! |
Updates
Hi, I'm a SvelteKit maintainer and got pointed to various issues with SvelteKit compatibility such as metonym/carbon-charts-svelte-examples#1 and #1148
Svelte packages should only distribute ESM.
main
andsvelte
should point to the same thingAlso, UMD should only be used if you want to use it in a browser
<script>
tag. CJS generally has far better compatibility with bundlers and with Node.jsDemo screenshot or recording
N/A
Review checklist (for reviewers only)