fix build issues
This commit is contained in:
parent
c94275bfe4
commit
ffe625ade8
2 changed files with 17 additions and 8 deletions
|
|
@ -3,32 +3,38 @@
|
||||||
* WebGL-based audio visualization using the Butterchurn library
|
* WebGL-based audio visualization using the Butterchurn library
|
||||||
*/
|
*/
|
||||||
import butterchurn from 'butterchurn';
|
import butterchurn from 'butterchurn';
|
||||||
import butterchurnPresets from 'butterchurn-presets';
|
|
||||||
import { visualizerSettings } from '../storage.js';
|
import { visualizerSettings } from '../storage.js';
|
||||||
import { audioContextManager } from '../audio-context.js';
|
import { audioContextManager } from '../audio-context.js';
|
||||||
|
|
||||||
// Module-level preset cache - loads immediately when this file is imported
|
// Module-level preset cache - loads immediately when this file is imported
|
||||||
let cachedPresets = null;
|
let cachedPresets = null;
|
||||||
let cachedPresetKeys = [];
|
let cachedPresetKeys = [];
|
||||||
|
let isLoading = false;
|
||||||
let loadCallbacks = [];
|
let loadCallbacks = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load presets at module level using static import
|
* Load presets at module level using dynamic import (lazy loaded)
|
||||||
*/
|
*/
|
||||||
function loadPresetsModule() {
|
async function loadPresetsModule() {
|
||||||
|
if (cachedPresets || isLoading) return;
|
||||||
|
isLoading = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('[Butterchurn] Loading presets module, export type:', typeof butterchurnPresets);
|
// Dynamic import to code-split butterchurn-presets into separate chunk
|
||||||
|
const butterchurnPresets = await import('butterchurn-presets');
|
||||||
|
console.log('[Butterchurn] Presets module loaded, type:', typeof butterchurnPresets);
|
||||||
|
|
||||||
// The module has a static getPresets method
|
// The module has a static getPresets method
|
||||||
if (typeof butterchurnPresets.getPresets !== 'function') {
|
if (typeof butterchurnPresets.default?.getPresets !== 'function') {
|
||||||
console.error(
|
console.error(
|
||||||
'[Butterchurn] butterchurnPresets.getPresets is not a function:',
|
'[Butterchurn] butterchurnPresets.getPresets is not a function:',
|
||||||
typeof butterchurnPresets.getPresets
|
typeof butterchurnPresets.default?.getPresets
|
||||||
);
|
);
|
||||||
|
isLoading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const allPresets = butterchurnPresets.getPresets();
|
const allPresets = butterchurnPresets.default.getPresets();
|
||||||
cachedPresets = allPresets || {};
|
cachedPresets = allPresets || {};
|
||||||
cachedPresetKeys = Object.keys(cachedPresets);
|
cachedPresetKeys = Object.keys(cachedPresets);
|
||||||
|
|
||||||
|
|
@ -53,6 +59,8 @@ function loadPresetsModule() {
|
||||||
console.error('[Butterchurn] Failed to load presets:', e);
|
console.error('[Butterchurn] Failed to load presets:', e);
|
||||||
cachedPresets = {};
|
cachedPresets = {};
|
||||||
cachedPresetKeys = [];
|
cachedPresetKeys = [];
|
||||||
|
} finally {
|
||||||
|
isLoading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +82,7 @@ export function onButterchurnPresetsLoaded(callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start loading presets immediately when module is imported
|
// Start loading presets immediately when module is imported (lazy loaded)
|
||||||
loadPresetsModule();
|
loadPresetsModule();
|
||||||
|
|
||||||
export class ButterchurnPreset {
|
export class ButterchurnPreset {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ export default defineConfig({
|
||||||
workbox: {
|
workbox: {
|
||||||
globPatterns: ['**/*.{js,css,html,ico,png,svg,json}'],
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,json}'],
|
||||||
cleanupOutdatedCaches: true,
|
cleanupOutdatedCaches: true,
|
||||||
|
maximumFileSizeToCacheInBytes: 3 * 1024 * 1024, // 3 MiB limit
|
||||||
// Define runtime caching strategies
|
// Define runtime caching strategies
|
||||||
runtimeCaching: [
|
runtimeCaching: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue