From 2037fe8964cfe033a0f8c5d215cd2cb1add8764a Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Tue, 1 Jun 2021 15:15:09 +0000 Subject: [PATCH] Add an error for unsupported usage of `new URL` --- rollup.config.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index 815c65ad..394b4277 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -33,11 +33,23 @@ import initialCssPlugin from './lib/initial-css-plugin'; import serviceWorkerPlugin from './lib/sw-plugin'; import dataURLPlugin from './lib/data-url-plugin'; import entryDataPlugin, { fileNameToURL } from './lib/entry-data-plugin'; +import dedent from 'dedent'; function resolveFileUrl({ fileName }) { return JSON.stringify(fileNameToURL(fileName)); } +function resolveImportMetaUrlInStaticBuild(property, { moduleId }) { + if (property !== 'url') return; + throw new Error(dedent` + Attempted to use a \`new URL(..., import.meta.url)\` pattern in ${path.relative( + process.cwd(), + moduleId, + )} for URL that needs to end up in static HTML. + This is currently unsupported. + `); +} + const dir = '.tmp/build'; const staticPath = 'static/c/[name]-[hash][extname]'; const jsPath = staticPath.replace('[extname]', '.js'); @@ -100,7 +112,7 @@ export default async function ({ watch }) { }, preserveModules: true, plugins: [ - { resolveFileUrl }, + { resolveFileUrl, resolveImportMeta: resolveImportMetaUrlInStaticBuild }, clientBundlePlugin( { external: ['worker_threads'],