From 3f33c33e0bbe85e6ee6510079f4ee5421fda69eb Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Tue, 31 Dec 2024 13:24:29 -0600 Subject: [PATCH] refactor: Silence Rollup warnings regarding source maps & use directives --- src/index.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8063bcf..98b0edc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -153,9 +153,23 @@ function preactPlugin({ build: { rollupOptions: { onwarn(warning, warn) { - // Silence Rollup's module-level directive warnings -- they're likely - // to all come from `node_modules` (RSCs) and won't be actionable. - if (warning.code === "MODULE_LEVEL_DIRECTIVE") return; + // Silence Rollup's module-level directive warnings re:"use client". + // They're likely to come from `node_modules` and won't be actionable. + if ( + warning.code === "MODULE_LEVEL_DIRECTIVE" && + warning.message.includes("use client") + ) + return; + // ESBuild seemingly doesn't include mappings for directives, causing + // Rollup to emit warnings about missing source locations. This too is + // likely to come from `node_modules` and won't be actionable. + // evanw/esbuild#3548 + if ( + warning.code === "SOURCEMAP_ERROR" && + warning.message.includes("resolve original location") && + warning.pos === 0 + ) + return; warn(warning); }, },