File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed
Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,13 @@ export const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {
204204 config : ( config , env ) => {
205205 const isDev = env . command === 'serve'
206206
207+ const shimsToInject = {
208+ // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md#vite
209+ ...( isEnabled ( optionsResolved . globals . Buffer , 'build' ) ? { Buffer : 'vite-plugin-node-polyfills/shims/buffer' } : { } ) ,
210+ ...( isEnabled ( optionsResolved . globals . global , 'build' ) ? { global : 'vite-plugin-node-polyfills/shims/global' } : { } ) ,
211+ ...( isEnabled ( optionsResolved . globals . process , 'build' ) ? { process : 'vite-plugin-node-polyfills/shims/process' } : { } ) ,
212+ }
213+
207214 return {
208215 build : {
209216 rollupOptions : {
@@ -216,16 +223,7 @@ export const nodePolyfills = (options: PolyfillOptions = {}): Plugin => {
216223 rollupWarn ( warning )
217224 } )
218225 } ,
219- plugins : [
220- {
221- ...inject ( {
222- // https://github.com/niksy/node-stdlib-browser/blob/3e7cd7f3d115ac5c4593b550e7d8c4a82a0d4ac4/README.md#vite
223- ...( isEnabled ( optionsResolved . globals . Buffer , 'build' ) ? { Buffer : 'vite-plugin-node-polyfills/shims/buffer' } : { } ) ,
224- ...( isEnabled ( optionsResolved . globals . global , 'build' ) ? { global : 'vite-plugin-node-polyfills/shims/global' } : { } ) ,
225- ...( isEnabled ( optionsResolved . globals . process , 'build' ) ? { process : 'vite-plugin-node-polyfills/shims/process' } : { } ) ,
226- } ) ,
227- } ,
228- ] ,
226+ plugins : Object . keys ( shimsToInject ) . length > 0 ? [ inject ( shimsToInject ) ] : [ ] ,
229227 } ,
230228 } ,
231229 esbuild : {
You can’t perform that action at this time.
0 commit comments