add vite-plugin-bundle-audioworklet and use it both from website and superdough
This commit is contained in:
parent
7bec92ca99
commit
fdbbcd2dd2
7 changed files with 44 additions and 8 deletions
|
|
@ -0,0 +1,48 @@
|
|||
import { createLogger, build } from 'vite';
|
||||
|
||||
const end = '?audioworklet';
|
||||
|
||||
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}";`;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default bundleAudioWorkletPlugin;
|
||||
Loading…
Add table
Add a link
Reference in a new issue