You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Usually we need to add polyfills to be able to use 3rd party libraries such as algosdk.
I have created a script to easily do this, we can include this in the template:
// add-polyfills.mjs/* eslint-disable consistent-return */importutilfrom"util";import{exec}from"child_process";importfsfrom"fs";// promisify `exec` so we can "await" itconstexecAsync=util.promisify(exec);// content of config-overrides.js file to be addedconstCONFIG_OVERRIDES_CONTENT=`const webpack = require("webpack");module.exports = function override(config) { const fallback = config.resolve.fallback || {}; Object.assign(fallback, { crypto: require.resolve("crypto-browserify"), stream: require.resolve("stream-browserify"), buffer: require.resolve("buffer/"), }); config.resolve.fallback = fallback; config.ignoreWarnings = [/Failed to parse source map/]; config.plugins = (config.plugins || []).concat([ new webpack.ProvidePlugin({ process: "process/browser", Buffer: ["buffer", "Buffer"], }), ]); return config;};`;asyncfunctionmain(){awaitinstallReactAppRewired();createConfigOverrides();updateNpmScripts();}functioninstallReactAppRewired(){returnexecAsync("npm install react-app-rewired --save-dev",(error,stdout,stderr)=>{if(error){console.log(`ERROR while installing react-app-rewired: ${error.message}`);return;}if(stderr){console.log(`stderr: ${stderr}`);return;}console.log(`stdout: ${stdout}`);});}functioncreateConfigOverrides(){fs.writeFile("config-overrides.js",CONFIG_OVERRIDES_CONTENT,(err)=>{if(err){throwerr;}console.log("config-overrides.js was created successfully!");});}functionupdateNpmScripts(){// next line opens package json, updates start and other scripts to use react-app-rewired// and saves the filefs.readFile("package.json","utf8",(err,data)=>{if(err){returnconsole.log(err);}console.log(data);constresult=data.replace(/"start": "react-scripts start"/g,'"start": "react-app-rewired start"').replace(/"build": "react-scripts build"/g,'"build": "react-app-rewired build"').replace(/"test": "react-scripts test"/g,'"test": "react-app-rewired test"').replace(/"eject": "react-scripts eject"/g,'"eject": "react-app-rewired eject"');fs.writeFile("package.json",result,{encoding: "utf8",// "w" so it will overwriteflag: "w"},(writeError)=>{if(writeError){returnconsole.log(writeError);}});});}main();
run:
node add-polyfills.mjs
The text was updated successfully, but these errors were encountered:
Usually we need to add polyfills to be able to use 3rd party libraries such as
algosdk
.I have created a script to easily do this, we can include this in the template:
run:
The text was updated successfully, but these errors were encountered: