Skip to content

Commit

Permalink
fix: optimise highcharts bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-zippenfenig committed Nov 10, 2023
1 parent 6debabf commit cc77d22
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/lib/Elements/HighchartContainer.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import Highcharts, { Chart, StockChart, type Options } from 'highcharts/highstock';
import Highcharts, { Chart, type Options } from 'highcharts/highcharts';
import { onDestroy, onMount } from 'svelte';
import HighchartsAccessibility from 'highcharts/modules/accessibility';
//import HighchartsAccessibility from 'highcharts/modules/accessibility';
//import HighchartsStock from 'highcharts/modules/stock';
import { dev } from '$app/environment';
//import HighchartsBoost from "highcharts/modules/boost";
import { themeIsDark } from '$lib/stores';
Expand Down Expand Up @@ -29,14 +30,23 @@
const HighchartsDebugger = await import('highcharts/modules/debugger');
HighchartsDebugger.default(Highcharts);
}
HighchartsAccessibility(Highcharts);
//HighchartsAccessibility(Highcharts);
options.chart = options.chart || {};
options.chart.styledMode = true;
options.accessibility = {
enabled: false
};
options.credits = {
text: 'Open-Meteo.com',
href: 'http://open-meteo.com'
};
chart = useStockChart ? new StockChart(node, options) : new Chart(node, options);
if (useStockChart) {
const HighchartsStock = await import('highcharts/modules/stock');
HighchartsStock.default(Highcharts);
chart = new Highcharts.StockChart(node, options);
} else {
chart = new Chart(node, options);
}
});
onDestroy(() => {
Expand Down
21 changes: 21 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

// Make sure highcharts and highstock are bundled separately
function manualChunks(id) {
//return `${id}`.replace('/','_');
if (id.includes('stock.js')) {
return 'highstock'
}
if (id.includes('highcharts')) {
return 'highcharts'
}
/*if (id.includes('node_modules')) {
return 'vendor';
}*/
}

export default defineConfig({
plugins: [sveltekit()],

Expand All @@ -10,5 +24,12 @@ export default defineConfig({
additionalData: '@use "src/variables.scss" as *;'
}
}
},
build: {
rollupOptions: {
output: {
manualChunks: manualChunks
}
}
}
});

0 comments on commit cc77d22

Please sign in to comment.