Skip to content

Commit fc03122

Browse files
committed
Move global shim banners into utils
1 parent 36c618a commit fc03122

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/index.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type ModuleNameWithoutNodePrefix,
1111
type TransformHook,
1212
compareModuleNames,
13+
globalShimBanners,
1314
isEnabled,
1415
isNodeProtocolImport,
1516
toRegExp,
@@ -92,21 +93,6 @@ export type PolyfillOptionsResolved = {
9293
protocolImports: boolean,
9394
}
9495

95-
const globalShimBanners = {
96-
buffer: [
97-
`import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'`,
98-
`globalThis.Buffer = globalThis.Buffer || __buffer_polyfill`,
99-
],
100-
global: [
101-
`import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'`,
102-
`globalThis.global = globalThis.global || __global_polyfill`,
103-
],
104-
process: [
105-
`import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'`,
106-
`globalThis.process = globalThis.process || __process_polyfill`,
107-
],
108-
}
109-
11096
/**
11197
* Returns a Vite plugin to polyfill Node's Core Modules for browser environments. Supports `node:` protocol imports.
11298
*

src/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ export const compareModuleNames = (moduleA: ModuleName, moduleB: ModuleName) =>
1111
return withoutNodeProtocol(moduleA) === withoutNodeProtocol(moduleB)
1212
}
1313

14+
export const globalShimBanners = {
15+
buffer: [
16+
`import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'`,
17+
`globalThis.Buffer = globalThis.Buffer || __buffer_polyfill`,
18+
],
19+
global: [
20+
`import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'`,
21+
`globalThis.global = globalThis.global || __global_polyfill`,
22+
],
23+
process: [
24+
`import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'`,
25+
`globalThis.process = globalThis.process || __process_polyfill`,
26+
],
27+
}
28+
1429
export const isEnabled = (value: BooleanOrBuildTarget, target: BuildTarget) => {
1530
if (!value) return false
1631
if (value === true) return true

0 commit comments

Comments
 (0)