wasm-bindgen-rayon and new OMT plugin (#1007)

* WIP: wasm-bindgen-rayon and new OMT plugin

* Bump package-lock

* Make OMT work again

* Update year

* Restore accidental change

* Prevent minification of `nextDefineUri`

* Delay loading external deps

This gives inline `define` calls a chance to define dependencies for earlier `define` calls on the same page.

* Add comment
This commit is contained in:
Ingvar Stepanyan
2021-05-13 13:50:31 +01:00
committed by GitHub
parent ff9dea465f
commit b9b6e57581
24 changed files with 441 additions and 308 deletions

View File

@@ -37,13 +37,6 @@ function resolveFileUrl({ fileName }) {
return JSON.stringify(fileName.replace(/^static\//, '/'));
}
// With AMD output, Rollup always uses document.baseURI, which breaks in workers.
// This fixes it:
function resolveImportMeta(property, { chunkId }) {
if (property !== 'url') return;
return `new URL(${resolveFileUrl({ fileName: chunkId })}, location).href`;
}
const dir = '.tmp/build';
const staticPath = 'static/c/[name]-[hash][extname]';
const jsPath = staticPath.replace('[extname]', '.js');
@@ -62,6 +55,7 @@ export default async function ({ watch }) {
path.join(__dirname, 'lib', 'omt.ejs'),
'utf-8',
);
await del('.tmp/build');
const isProduction = !watch;
@@ -83,7 +77,7 @@ export default async function ({ watch }) {
]),
urlPlugin(),
dataURLPlugin(),
cssPlugin(resolveFileUrl),
cssPlugin(),
];
return {
@@ -105,12 +99,12 @@ export default async function ({ watch }) {
},
preserveModules: true,
plugins: [
{ resolveFileUrl, resolveImportMeta },
{ resolveFileUrl },
clientBundlePlugin(
{
external: ['worker_threads'],
plugins: [
{ resolveFileUrl, resolveImportMeta },
{ resolveFileUrl },
OMT({ loader: await omtLoaderPromise }),
serviceWorkerPlugin({
output: 'static/serviceworker.js',