fix: superdough worklets bundling
This commit is contained in:
parent
5702914661
commit
7bec92ca99
3 changed files with 49 additions and 2 deletions
|
|
@ -8,7 +8,7 @@ import './feedbackdelay.mjs';
|
|||
import './reverb.mjs';
|
||||
import './vowel.mjs';
|
||||
import { clamp, nanFallback, _mod } from './util.mjs';
|
||||
import workletsUrl from './worklets.mjs?worker&url';
|
||||
import workletsUrl from './worklets.mjs?audioworklet';
|
||||
import { createFilter, gainNode, getCompressor, getWorklet } from './helpers.mjs';
|
||||
import { map } from 'nanostores';
|
||||
import { logger } from './logger.mjs';
|
||||
|
|
|
|||
46
packages/superdough/vite-plugin-bundle-audioworklet.js
Normal file
46
packages/superdough/vite-plugin-bundle-audioworklet.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { createLogger, build } from 'vite';
|
||||
|
||||
const end = '?audioworklet';
|
||||
|
||||
export function bundleAudioWorkletPlugin() /* : PluginOption */ {
|
||||
let viteConfig /* : UserConfig */;
|
||||
|
||||
return {
|
||||
name: 'vite-plugin-bundle-audioworklet',
|
||||
apply: 'build',
|
||||
enforce: 'post',
|
||||
|
||||
config(config) {
|
||||
viteConfig = config;
|
||||
},
|
||||
|
||||
async transform(_code, id) {
|
||||
if (!id.endsWith(end)) {
|
||||
return;
|
||||
}
|
||||
const entry = id.replace(end, '');
|
||||
const quietLogger = createLogger();
|
||||
quietLogger.info = () => undefined;
|
||||
|
||||
const output = await build({
|
||||
configFile: false,
|
||||
clearScreen: false,
|
||||
customLogger: quietLogger,
|
||||
build: {
|
||||
lib: {
|
||||
entry,
|
||||
name: '_',
|
||||
formats: ['iife'],
|
||||
},
|
||||
write: false,
|
||||
},
|
||||
});
|
||||
if (!(output instanceof Array)) {
|
||||
throw new Error('Expected output to be Array');
|
||||
}
|
||||
const iife = output[0].output[0].code;
|
||||
const encoded = Buffer.from(iife, 'utf8').toString('base64');
|
||||
return `export default "data:text/javascript;base64,${encoded}";`;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
import { defineConfig } from 'vite';
|
||||
import { dependencies } from './package.json';
|
||||
import { resolve } from 'path';
|
||||
import { bundleAudioWorkletPlugin } from './vite-plugin-bundle-audioworklet';
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [],
|
||||
plugins: [bundleAudioWorkletPlugin()],
|
||||
build: {
|
||||
lib: {
|
||||
entry: resolve(__dirname, 'index.mjs'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue