Giter VIP home page Giter VIP logo

Comments (2)

jwnx avatar jwnx commented on September 22, 2024

Maybe dupe of #71 ?

from vite-plugin-node-polyfills.

sa3dany avatar sa3dany commented on September 22, 2024

If anyone is facing this, In our app we are in the process of migrating from create-react-app to Vite and I created this package patch (it's for v0.21.0 only) as an interim solution.

diff --git a/node_modules/vite-plugin-node-polyfills/dist/index.cjs b/node_modules/vite-plugin-node-polyfills/dist/index.cjs
index fef08f0..13aefe5 100644
--- a/node_modules/vite-plugin-node-polyfills/dist/index.cjs
+++ b/node_modules/vite-plugin-node-polyfills/dist/index.cjs
@@ -1,3 +1,3 @@
-"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("node:module"),y=require("@rollup/plugin-inject"),B=require("node-stdlib-browser"),x=require("node-stdlib-browser/helpers/rollup/plugin"),P=require("node-stdlib-browser/helpers/esbuild/plugin");var a=typeof document<"u"?document.currentScript:null;const d=e=>e&&e.__esModule?e:{default:e},T=d(y),j=d(B),q=d(P),b=(e,r)=>p(e)===p(r),i=(e,r)=>e?e===!0?!0:e===r:!1,R=e=>e.startsWith("node:"),S=e=>{const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^${r}$`)},p=e=>e.replace(/^node:/,""),g=["import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'","import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'","import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'","","globalThis.Buffer = globalThis.Buffer || __buffer_polyfill","globalThis.global = globalThis.global || __global_polyfill","globalThis.process = globalThis.process || __process_polyfill",""].join(`
+"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("node:module"),y=require("@rollup/plugin-inject"),B=require("node-stdlib-browser"),x=require("node-stdlib-browser/helpers/rollup/plugin"),P=require("node-stdlib-browser/helpers/esbuild/plugin");var a=typeof document<"u"?document.currentScript:null;const d=e=>e&&e.__esModule?e:{default:e},T=d(y),j=d(B),q=d(P),b=(e,r)=>p(e)===p(r),i=(e,r)=>e?e===!0?!0:e===r:!1,R=e=>e.startsWith("node:"),S=e=>{const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^${r}$`)},p=e=>e.replace(/^node:/,""),g=["import __buffer_polyfill from 'vite-plugin-node-polyfills/shims/buffer'","import __global_polyfill from 'vite-plugin-node-polyfills/shims/global'","import __process_polyfill from 'vite-plugin-node-polyfills/shims/process'","","globalThis.Buffer = globalThis.Buffer || __buffer_polyfill","globalThis.global = globalThis.global || __global_polyfill","globalThis.process = globalThis.process?.env ? { ...__process_polyfill, env: globalThis.process.env } : __process_polyfill",""].join(`
 `),$=(e={})=>{const r=_.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:a&&a.src||new URL("index.cjs",document.baseURI).href),f=[r.resolve("vite-plugin-node-polyfills/shims/buffer"),r.resolve("vite-plugin-node-polyfills/shims/global"),r.resolve("vite-plugin-node-polyfills/shims/process")],l={include:[],exclude:[],overrides:{},protocolImports:!0,...e,globals:{Buffer:!0,global:!0,process:!0,...e.globals}},v=o=>l.include.length>0?!l.include.some(s=>b(o,s)):l.exclude.some(s=>b(o,s)),m=o=>{if(i(l.globals.Buffer,"dev")&&/^buffer$/.test(o))return"vite-plugin-node-polyfills/shims/buffer";if(i(l.globals.global,"dev")&&/^global$/.test(o))return"vite-plugin-node-polyfills/shims/global";if(i(l.globals.process,"dev")&&/^process$/.test(o))return"vite-plugin-node-polyfills/shims/process";if(o in l.overrides)return l.overrides[o]},c=Object.entries(j.default).reduce((o,[s,t])=>(!l.protocolImports&&R(s)||v(s)||(o[s]=m(p(s))||t),o),{});return{name:"vite-plugin-node-polyfills",config:(o,s)=>{const t=s.command==="serve";return{build:{rollupOptions:{onwarn:(n,u)=>{x.handleCircularDependancyWarning(n,()=>{if(o.build?.rollupOptions?.onwarn)return o.build.rollupOptions.onwarn(n,u);u(n)})},plugins:[{...T.default({...i(l.globals.Buffer,"build")?{Buffer:"vite-plugin-node-polyfills/shims/buffer"}:{},...i(l.globals.global,"build")?{global:"vite-plugin-node-polyfills/shims/global"}:{},...i(l.globals.process,"build")?{process:"vite-plugin-node-polyfills/shims/process"}:{}})}]}},esbuild:{banner:t?g:void 0},optimizeDeps:{exclude:[...f],esbuildOptions:{banner:t?{js:g}:void 0,define:{...t&&i(l.globals.Buffer,"dev")?{Buffer:"Buffer"}:{},...t&&i(l.globals.global,"dev")?{global:"global"}:{},...t&&i(l.globals.process,"dev")?{process:"process"}:{}},inject:[...f],plugins:[q.default(c),{name:"vite-plugin-node-polyfills-shims-resolver",setup(n){for(const u of f){const h=S(u);n.onResolve({filter:h},()=>({external:!1,path:u}))}}}]}},resolve:{alias:{...c}}}}}};exports.nodePolyfills=$;
 //# sourceMappingURL=index.cjs.map

from vite-plugin-node-polyfills.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.