In order to disable source maps in Vite so that users cannot view the code through the browser we need to do two things:

  1. Install the package cross-env: npm install --save-dev cross-env.
  2. In the scripts object in the package.json file add the following to the build command: cross-env GENERATE_SOURCEMAP=false vite build.
  3. In the vite config file vite.config.js or vite.config.ts add the following inside defineConfig: build: {sourcemap: false}.