Minify worker source
This commit is contained in:
@@ -29,26 +29,27 @@ async function build(input, {minify = true} = {}) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}),
|
})
|
||||||
{
|
|
||||||
name: 'serialize worker and export create function',
|
|
||||||
renderChunk(code) {
|
|
||||||
return `
|
|
||||||
const source = ${JSON.stringify(code)};
|
|
||||||
const blob = new Blob([source], {type: 'application/javascript'});
|
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
export function create() {
|
|
||||||
return new Worker(url);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (minify) {
|
if (minify) {
|
||||||
plugins.push(terser());
|
plugins.push(terser());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins.push({
|
||||||
|
name: 'serialize worker and export create function',
|
||||||
|
renderChunk(code) {
|
||||||
|
return `
|
||||||
|
const source = ${JSON.stringify(code)};
|
||||||
|
const blob = new Blob([source], {type: 'application/javascript'});
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
export function create() {
|
||||||
|
return new Worker(url);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const bundle = await rollup.rollup({input, plugins});
|
const bundle = await rollup.rollup({input, plugins});
|
||||||
const {output} = await bundle.generate({format: 'es'});
|
const {output} = await bundle.generate({format: 'es'});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user