Skip to content

Commit dc1861e

Browse files
authored
fix: remove Node polyfill by default (#2593)
This doesn't make sense in normal codebases where we try to detect whether we're in a Node or browser environment. It can be added back with a simple Vite config such as: ``` import { polyfillNode } from "esbuild-plugin-polyfill-node"; export default { optimizeDeps: { plugins: [polyfillNode()], } } ```
1 parent 816d7e0 commit dc1861e

File tree

9 files changed

+102
-43
lines changed

9 files changed

+102
-43
lines changed

core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"@previewjs/vfs": "^2.1.4",
3333
"assert-never": "^1.3.0",
3434
"axios": "^1.7.9",
35-
"esbuild-plugin-polyfill-node": "^0.3.0",
3635
"exclusive-promises": "^1.0.3",
3736
"express": "^4.21.2",
3837
"fs-extra": "^11.2.0",

core/src/vite/vite-manager.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
ReaderListenerInfo,
1212
} from "@previewjs/vfs";
1313
import type { Alias } from "@rollup/plugin-alias";
14-
import { polyfillNode } from "esbuild-plugin-polyfill-node";
1514
import { exclusivePromiseRunner } from "exclusive-promises";
1615
import express from "express";
1716
import fs from "fs-extra";
@@ -369,14 +368,6 @@ export class ViteManager {
369368
...config.vite,
370369
configFile: false,
371370
root: this.options.rootDir,
372-
optimizeDeps: {
373-
entries: [],
374-
esbuildOptions: {
375-
// TODO: Remove this annotation once upgraded to Vite 5.
376-
// @ts-ignore incompatible esbuild versions with Vite 4
377-
plugins: [polyfillNode()],
378-
},
379-
},
380371
server: {
381372
middlewareMode: true,
382373
hmr: {
@@ -428,6 +419,7 @@ export class ViteManager {
428419
define: {
429420
__filename: undefined,
430421
__dirname: undefined,
422+
process: undefined,
431423
...frameworkPluginViteConfig.define,
432424
...existingViteConfig?.config.define,
433425
...config.vite?.define,

framework-plugins/preact/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@previewjs/storybook-helpers": "^6.0.1",
3131
"@previewjs/type-analyzer": "^10.1.5",
3232
"@previewjs/vfs": "^2.1.4",
33+
"esbuild-plugin-polyfill-node": "^0.3.0",
3334
"typescript": "^5.7.2"
3435
},
3536
"devDependencies": {

framework-plugins/preact/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Component, Story } from "@previewjs/analyzer-api";
22
import type { FrameworkPluginFactory } from "@previewjs/core";
33
import { createTypeAnalyzer } from "@previewjs/type-analyzer";
4+
import { polyfillNode } from "esbuild-plugin-polyfill-node";
45
import path from "path";
56
import ts from "typescript";
67
import url from "url";
@@ -65,6 +66,11 @@ const preactFrameworkPlugin: FrameworkPluginFactory = {
6566
},
6667
viteConfig: (configuredPlugins) => {
6768
return {
69+
optimizeDeps: {
70+
esbuildOptions: {
71+
plugins: [polyfillNode()],
72+
},
73+
},
6874
resolve: {
6975
alias: {
7076
react: "preact/compat",

framework-plugins/react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
},
2525
"dependencies": {
2626
"@previewjs/analyzer-react": "^0.1.11",
27-
"@vitejs/plugin-react": "^4.3.4"
27+
"@vitejs/plugin-react": "^4.3.4",
28+
"esbuild-plugin-polyfill-node": "^0.3.0"
2829
},
2930
"devDependencies": {
3031
"@playwright/test": "^1.49.1",

framework-plugins/react/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createAnalyzer } from "@previewjs/analyzer-react";
22
import type { FrameworkPluginFactory } from "@previewjs/core";
33
import react from "@vitejs/plugin-react";
4+
import { polyfillNode } from "esbuild-plugin-polyfill-node";
45
import path from "path";
56
import url from "url";
67
import { reactImportsPlugin } from "./react-js-imports-plugin.js";
@@ -41,6 +42,11 @@ const reactFrameworkPlugin: FrameworkPluginFactory = {
4142
plugin.name.startsWith("vite:react-")
4243
);
4344
return {
45+
optimizeDeps: {
46+
esbuildOptions: {
47+
plugins: dependencies["next"] ? [polyfillNode()] : [],
48+
},
49+
},
4450
resolve: {
4551
alias: {
4652
"react-native": "react-native-web",

framework-plugins/svelte/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@previewjs/type-analyzer": "^10.1.5",
3232
"@previewjs/vfs": "^2.1.4",
3333
"@sveltejs/vite-plugin-svelte": "^5.0.2",
34+
"esbuild-plugin-polyfill-node": "^0.3.0",
3435
"fs-extra": "^11.2.0",
3536
"svelte": "^5.10.0",
3637
"typescript": "^5.7.2",

framework-plugins/svelte/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { FrameworkPluginFactory } from "@previewjs/core";
33
import { createTypeAnalyzer } from "@previewjs/type-analyzer";
44
import type sveltekit from "@sveltejs/kit";
55
import { svelte } from "@sveltejs/vite-plugin-svelte";
6+
import { polyfillNode } from "esbuild-plugin-polyfill-node";
67
import fs from "fs-extra";
78
import path from "path";
89
import url from "url";
@@ -74,6 +75,11 @@ const svelteFrameworkPlugin: FrameworkPluginFactory = {
7475
};
7576
},
7677
viteConfig: (configuredPlugins) => ({
78+
optimizeDeps: {
79+
esbuildOptions: {
80+
plugins: [polyfillNode()],
81+
},
82+
},
7783
...(isSvelteKit
7884
? {
7985
define: {

pnpm-lock.yaml

Lines changed: 79 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)