Skip to content

Instantly share code, notes, and snippets.

@davidramos-om
Last active March 29, 2023 01:34
Show Gist options
  • Save davidramos-om/be3c0fbdee665e369d733ee59fd041db to your computer and use it in GitHub Desktop.
Save davidramos-om/be3c0fbdee665e369d733ee59fd041db to your computer and use it in GitHub Desktop.
react app : vite.config + nodePolyfills (fs, process, buffer for orbit-db and ipfs)
import { defineConfig } from 'vite'
import path from 'path';
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths';
import Pages from 'vite-plugin-pages'
import eslint from 'vite-plugin-eslint';
import { nodePolyfills } from 'vite-plugin-node-polyfills'
//! NOTES : ABOUT POLYFILL fs, process, buffer for orbit-db and ipfs
//* - nodePolyfills from "vite-plugin-node-stdlib-browser" works well for development, but not for live
//* - nodePolyfills from "vite-plugin-node-polyfills" seems to work well for both development and live
//* - it looks like is not needed to set up the esbuildOptions for optimizeDeps
//* - it looks like is {protocolImports: true} is not needed.
//* - More complex polyfills using optimizeDeps, build, rollup, etc. did not work for me when it comes to build for production.
//! https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
'~/': path.resolve(__dirname, './src/*'),
}
},
plugins: [
react({
include: "**/*.tsx"
}),
Pages({ dirs: 'src/pages' }),
eslint(),
tsconfigPaths(),
nodePolyfills(),
],
});
@davidramos-om
Copy link
Author

package.json as follows :

  "dependencies": {
    "@chakra-ui/icons": "^2.0.17",
    "@chakra-ui/react": "^2.5.4",
    "date-fns": "^2.29.3",
    "eslint": "^8.37.0",
    "eslint-config-react-app": "^7.0.1",
    "ipfs-core": "^0.18.0",
    "orbit-db": "^0.29.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.9.0",
    "react-virtuoso": "^4.1.0",
    "sweetalert2": "^11.7.3",
    "sweetalert2-react-content": "^5.0.7",
    "uuid": "^9.0.0",
    "vite-plugin-node-polyfills": "^0.7.0",
    "vite-plugin-pages": "^0.29.0",
    "vite-tsconfig-paths": "^4.0.7"
  },
  "devDependencies": {
    "@types/orbit-db": "https://github.com/orbitdb/orbit-db-types.git",
    "@types/react": "^18.0.31",
    "@types/react-dom": "^18.0.11",
    "@types/uuid": "^9.0.1",
    "@vitejs/plugin-react": "^3.1.0",
    "typescript": "^5.0.2",
    "vite": "^4.2.1",
    "vite-plugin-eslint": "^1.8.1"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment