Skip to content

Commit 2037fe8

Browse files
committed
Add an error for unsupported usage of new URL
1 parent d07c57e commit 2037fe8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

rollup.config.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,23 @@ import initialCssPlugin from './lib/initial-css-plugin';
3333
import serviceWorkerPlugin from './lib/sw-plugin';
3434
import dataURLPlugin from './lib/data-url-plugin';
3535
import entryDataPlugin, { fileNameToURL } from './lib/entry-data-plugin';
36+
import dedent from 'dedent';
3637

3738
function resolveFileUrl({ fileName }) {
3839
return JSON.stringify(fileNameToURL(fileName));
3940
}
4041

42+
function resolveImportMetaUrlInStaticBuild(property, { moduleId }) {
43+
if (property !== 'url') return;
44+
throw new Error(dedent`
45+
Attempted to use a \`new URL(..., import.meta.url)\` pattern in ${path.relative(
46+
process.cwd(),
47+
moduleId,
48+
)} for URL that needs to end up in static HTML.
49+
This is currently unsupported.
50+
`);
51+
}
52+
4153
const dir = '.tmp/build';
4254
const staticPath = 'static/c/[name]-[hash][extname]';
4355
const jsPath = staticPath.replace('[extname]', '.js');
@@ -100,7 +112,7 @@ export default async function ({ watch }) {
100112
},
101113
preserveModules: true,
102114
plugins: [
103-
{ resolveFileUrl },
115+
{ resolveFileUrl, resolveImportMeta: resolveImportMetaUrlInStaticBuild },
104116
clientBundlePlugin(
105117
{
106118
external: ['worker_threads'],

0 commit comments

Comments
 (0)