In order to disable source maps in Vite so that users cannot view the code through the browser we need to do two things:
- Install the package
cross-env
:npm install --save-dev cross-env
. - In the
scripts
object in thepackage.json
file add the following to thebuild
command:cross-env GENERATE_SOURCEMAP=false vite build
. - In the vite config file
vite.config.js
orvite.config.ts
add the following insidedefineConfig
:build: {sourcemap: false}
.