-
Notifications
You must be signed in to change notification settings - Fork 6
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
Support Reduction of Bundle Size #7
Comments
I think that's on Here you can see
HOWEVER: Svelte appears to already be pruning the packages or something when you build the svelte project. Clone this repo and build it, the total final package size is 1.2M:
|
Thanks for your reply.
Same for me. But 384kB is waayyy to big for a bar chart graph |
You make a good point. I think you'd have to manually embed them in your project, or create a separate repo/npm package for each exported build from that. We could make something like I'd also have to remove |
I found this too, I'll look into it |
That would be really cool. |
Any new updates regarding the bundle size |
No, I've tried but have been unsuccessful getting this to tree shake effectively. I might need help on this one |
Thank you for your effort. Im not sure if I am helpful. But if you need another hand let me know |
@MuslemRahimi that would be very helpful if you could take a look at it |
UPDATE Bad news, looks like Maybe there is a way to get The issue appears to be related to the way
Looks like it is working in When using the recommended Here's the work I've done in a new branch for testing: svelte-echarts/src/lib/Chart.svelte Line 2 in ee1ee4c
It produces this error:
|
Not sure if this helps, I was able to get the reduced bundle size working with Echarts in Sveltekit with the subset of the library: https://echarts.apache.org/en/builder.html by adding it to my app.html like this:
While this works it is not ideal for me as I only want to load echarts it in my charts component, not for the whole app. Still I'm using this for now. It might be more useful for someone that doesn't have this requirement of only wanting to load it dynamically. All my attempts to load it dynamically resulted in File '/etc/echarts.js' is not a module errors not sure if there is a way to wrap the file so that it doesn't complain about this, or some other technique for loading the file. |
Can you share your full code. I couldn't reproduce it yet! |
here is my src/app.html:
my component, I'm new to SvelteKit so not sure I'm doing everything correctly but it works for me:
|
This is interesting it looks like a fix for this is in v 5.5.rc1, not sure when 5.5 will get released but good news when it does I think it may solve the issue, granted once/if the implementation details are worked out. Would be nice if this could work in Sveltekit with |
I did not know about this pull request. Really nice. @bherbruck can we add this to your library? |
@vdiff looks like that will fix it as ESM errors are exactly the problem! @MuslemRahimi do you want to switch to a release candidate now? Maybe we can make our own rc version denoting the inclusion of the echarts rc? I think the branch is public if you want to see if the build succeeds on the echarts 5.5 rc1 version from NPM. |
sounds good. I think adding our own rc version would be better and quicker before the actual stable release of echarts. |
Looks like that works! The only thing to think about now is how we handle whether to make tree shaking optional or required. Here's the working version of the demo code from the repo: <script lang="ts">
import * as echarts from 'echarts/core'
import { BarChart } from 'echarts/charts'
import { GridComponent } from 'echarts/components'
import { CanvasRenderer } from 'echarts/renderers'
echarts.use([BarChart, GridComponent, CanvasRenderer])
import { Chart, type EChartsOptions } from '$lib'
const options: EChartsOptions = {
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
type: 'category',
},
yAxis: {
type: 'value',
},
series: [
{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'bar',
},
],
}
</script>
<div class="app">
<Chart {options} />
</div>
<style>
.app {
width: 100vw;
height: 100vh;
}
</style> Bundle size is almost 4x smaller! |
If anyone wants to update the tests, feel free |
Nice one, that's awesome, look forward to using it! That codegen is cool, I hadn't seen that. I have used this library echarts-for-react with React and it's pretty nice. They don't have a codegen like that though, and honestly it has tripped me up a couple times trying to figure out what all I'm using, like I didn't think mark lines etc would need to import a component but they do. Anyway they provide a nice list of options, not sure if it makes sense to do something like that, although that codegen is pretty sweet.
|
I am happy to update the tests or at least take a stab at it, but with work stuff I may not have time for a few days, so kinda depends on how fast you want it. |
"injecting" the echarts instance and having this wrapper as essentially type/api-only may be a good way to do it! I really like that. All the tests could probably pass in that scenario too, they're super simple though. The only thing we might lose is some actions/reactivity stuff I've been working on, maybe not though. |
Glad to hear that you might have been able to glean some techniques from the react echarts library. Hope that works out. I wasn't really sure if you still wanted help with writing tests or anything like that, but let me know if there is anything I can contribute. |
Time is tight right now, I could use the help |
I have been trying to help with this a bit this week, time is tight for me too with work but I can work on it a bit in free time, I tried RC2 for 5.5 thinking it might help with some of the typing, release notes seemed like it might. So far haven't had much luck. I'm going to keep messing with it, will keep you posted if I have any luck, so far mostly just trying to get the tests to run. |
Any new updates regarding the bundle size? |
Echarts 5.5.0 was officially released last week. I've been using it. Trying to get the tests to run with the new tree shaking branch, so far only got the first test to run. Finding it hard so far to get the other tests to run with the same echarts instance. Haven't had much time, but will continue to try when I can. |
Thanks for the heads up :) |
This is implemented in v1.0.0-rc1 ~50% reduction in bundle size <script>
import { Chart } from 'svelte-echarts'
import { init, use } from 'echarts/core'
import type { EChartsOption } from 'echarts'
import { BarChart } from 'echarts/charts'
import { GridComponent, TitleComponent } from 'echarts/components'
import { CanvasRenderer } from 'echarts/renderers'
// now with tree-shaking
use([BarChart, GridComponent, CanvasRenderer, TitleComponent])
let options = {
// some options...
}
</script>
<div class="app">
<Chart {init} {options} />
</div> |
Hi,
I only use specific components of the Chart.js libary.
Is it possible in your svelte wrapper library to support the reduction/selection of specific components of Chart.js.
The library is quite big and any form of reduction would be awesome
The text was updated successfully, but these errors were encountered: