Skip to content

Commit 99edac2

Browse files
authored
Fix broken webpack/next.js externals, add docs (#1722)
1 parent c2f6b09 commit 99edac2

5 files changed

Lines changed: 32 additions & 2 deletions

File tree

.changeset/sunny-years-knock.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@vanilla-extract/webpack-plugin': patch
3+
'@vanilla-extract/next-plugin': patch
4+
---
5+
6+
Fixes a bug where the `externals` option was silently ignored

packages/webpack-plugin/src/compiler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { LoaderContext } from './types';
22
import createCompat from './compat';
33

4-
// Should be "ExternalsItem" but webpack doesn't expose it
4+
// Webpack exposes the `Externals` type which is a union of several types.
5+
// We likely intended to only accept a subset of these, but chose to use `any`.
6+
// We handle potential array inputs, but really we should be more specific about what we accept
7+
// here, or handling all types. Changing this type would be a breaking change,
8+
// so we can look at this in a future major release.
59
type Externals = any;
610

711
interface CompilationResult {
@@ -131,7 +135,7 @@ function compileVanillaSource(
131135
new ExternalsPlugin('commonjs', [
132136
'@vanilla-extract/css',
133137
'@vanilla-extract/css/fileScope',
134-
externals,
138+
...(Array.isArray(externals) ? externals : [externals]),
135139
]).apply(childCompiler);
136140

137141
let source: string;

packages/webpack-plugin/src/plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export interface PluginOptions {
5757
test?: RuleSetRule['test'];
5858
identifiers?: IdentifierOption;
5959
outputCss?: boolean;
60+
/**
61+
* Effectively `ExternalItem[]` from webpack. Currently typed as `any` as this type was
62+
* previously not exposed. The `any` type will be fixed in the next major version.
63+
*/
6064
externals?: any;
6165
/** @deprecated */
6266
allowRuntime?: boolean;

site/docs/integrations/next.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ const withVanillaExtract = createVanillaExtractPlugin({
7676

7777
Each integration will set a default value based on the configuration options passed to the bundler.
7878

79+
### externals
80+
81+
Effectively [`ExternalItem[]`] from webpack.
82+
Currently typed as `any` as this type was previously not exposed.
83+
The `any` type will be fixed in the next major version.
84+
85+
[`ExternalItem[]`]: https://github.com/webpack/webpack/blob/9211be0f7a04feb45e1074e6cf848a657dd82ebc/declarations/WebpackOptions.d.ts#L207-L211
86+
7987
### unstable_turbopack
8088

8189
> ⚠️  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.

site/docs/integrations/webpack.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ new VanillaExtractPlugin({
102102
```
103103

104104
Each integration will set a default value based on the configuration options passed to the bundler.
105+
106+
### externals
107+
108+
Effectively [`ExternalItem[]`] from webpack.
109+
Currently typed as `any` as this type was previously not exposed.
110+
The `any` type will be fixed in the next major version.
111+
112+
[`ExternalItem[]`]: https://github.com/webpack/webpack/blob/9211be0f7a04feb45e1074e6cf848a657dd82ebc/declarations/WebpackOptions.d.ts#L207-L211

0 commit comments

Comments
 (0)