From efe155a8208de5a6fb05ab8e38f7d5f5fa927745 Mon Sep 17 00:00:00 2001 From: Adam Skoufis Date: Sun, 12 Apr 2026 20:10:03 +1000 Subject: [PATCH 1/2] Fix broken webpack/next.js `externals` --- .changeset/sunny-years-knock.md | 6 ++++++ packages/webpack-plugin/src/compiler.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/sunny-years-knock.md diff --git a/.changeset/sunny-years-knock.md b/.changeset/sunny-years-knock.md new file mode 100644 index 000000000..c1f863cbd --- /dev/null +++ b/.changeset/sunny-years-knock.md @@ -0,0 +1,6 @@ +--- +'@vanilla-extract/webpack-plugin': patch +'@vanilla-extract/next-plugin': patch +--- + +Fixes a bug where the `externals` option was silently ignored diff --git a/packages/webpack-plugin/src/compiler.ts b/packages/webpack-plugin/src/compiler.ts index ad32c842c..aca7f84cb 100644 --- a/packages/webpack-plugin/src/compiler.ts +++ b/packages/webpack-plugin/src/compiler.ts @@ -1,7 +1,11 @@ import type { LoaderContext } from './types'; import createCompat from './compat'; -// Should be "ExternalsItem" but webpack doesn't expose it +// Webpack exposes the `Externals` type which is a union of several types. +// We likely intended to only accept a subset of these, but chose to use `any`. +// We handle potential array inputs, but really we should be more specific about what we accept +// here, or handling all types. Changing this type would be a breaking change, +// so we can look at this in a future major release. type Externals = any; interface CompilationResult { @@ -131,7 +135,7 @@ function compileVanillaSource( new ExternalsPlugin('commonjs', [ '@vanilla-extract/css', '@vanilla-extract/css/fileScope', - externals, + ...(Array.isArray(externals) ? externals : [externals]), ]).apply(childCompiler); let source: string; From 8619661b3f742b76885805ad41c9954ab092213c Mon Sep 17 00:00:00 2001 From: Adam Skoufis Date: Sun, 12 Apr 2026 20:34:34 +1000 Subject: [PATCH 2/2] Document `externals` option --- packages/webpack-plugin/src/plugin.ts | 4 ++++ site/docs/integrations/next.md | 8 ++++++++ site/docs/integrations/webpack.md | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/packages/webpack-plugin/src/plugin.ts b/packages/webpack-plugin/src/plugin.ts index e05495c98..1429650b0 100644 --- a/packages/webpack-plugin/src/plugin.ts +++ b/packages/webpack-plugin/src/plugin.ts @@ -57,6 +57,10 @@ export interface PluginOptions { test?: RuleSetRule['test']; identifiers?: IdentifierOption; outputCss?: boolean; + /** + * Effectively `ExternalItem[]` from webpack. Currently typed as `any` as this type was + * previously not exposed. The `any` type will be fixed in the next major version. + */ externals?: any; /** @deprecated */ allowRuntime?: boolean; diff --git a/site/docs/integrations/next.md b/site/docs/integrations/next.md index 3061e5314..cece6ac12 100644 --- a/site/docs/integrations/next.md +++ b/site/docs/integrations/next.md @@ -76,6 +76,14 @@ const withVanillaExtract = createVanillaExtractPlugin({ Each integration will set a default value based on the configuration options passed to the bundler. +### externals + +Effectively [`ExternalItem[]`] from webpack. +Currently typed as `any` as this type was previously not exposed. +The `any` type will be fixed in the next major version. + +[`ExternalItem[]`]: https://github.com/webpack/webpack/blob/9211be0f7a04feb45e1074e6cf848a657dd82ebc/declarations/WebpackOptions.d.ts#L207-L211 + ### unstable_turbopack > ⚠️  Turbopack support is experimental. Its API is unstable and may undergo breaking changes in non-major versions. Additionally, it may not handle all features supported by Next.js. diff --git a/site/docs/integrations/webpack.md b/site/docs/integrations/webpack.md index 33154f7dc..50b1be11a 100644 --- a/site/docs/integrations/webpack.md +++ b/site/docs/integrations/webpack.md @@ -102,3 +102,11 @@ new VanillaExtractPlugin({ ``` Each integration will set a default value based on the configuration options passed to the bundler. + +### externals + +Effectively [`ExternalItem[]`] from webpack. +Currently typed as `any` as this type was previously not exposed. +The `any` type will be fixed in the next major version. + +[`ExternalItem[]`]: https://github.com/webpack/webpack/blob/9211be0f7a04feb45e1074e6cf848a657dd82ebc/declarations/WebpackOptions.d.ts#L207-L211