If you are change the vite application port please follow the procedure.
"scripts": {
"dev": "vite --port 3006",
"build": "vite build",
"preview": "vite preview"
}
If you are change the vite application port please follow the procedure.
"scripts": {
"dev": "vite --port 3006",
"build": "vite build",
"preview": "vite preview"
}
Try add your port into vite.config.ts:
export default defineConfig({
// ...some configs
server: {
port: 3006,
},
});
vite
and not vite preview
. vite preview
does not look at that setting. –
Francie vite preview
looks at preview
, which is the identical config format to server
–
Alcoholize you can modify the dev script in the package.json
file and set the --port
to the one you want .
in vite.config.ts you can manage the port separately for production and development. PORT server: production. PORT preview: development
export default defineConfig({
//change port for production
preview: {
port: 3001,
},
// for dev
server: {
port: 3000,
},
});
In addition to defining it in the config or providing it on the command line, it's also possible to configure the port in .env
files - anything in .env
/ .env.production
etc that's prefixed with VITE_
will be automatically available to your app via import.meta.env
and can be loaded into the vite.config.ts
file using loadEnv
:
import react from '@vitejs/plugin-react';
import { ConfigEnv, defineConfig, loadEnv } from 'vite';
export default defineConfig(({command, mode} : ConfigEnv) => {
console.log(`configuring vite with command: ${command}, mode: ${mode}`);
// suppress eslint warning that process isn't defined (it is)
// eslint-disable-next-line
const cwd = process.cwd();
console.log(`loading envs from ${cwd} ...`);
const env = {...loadEnv(mode, cwd, 'VITE_')};
console.log(`loaded env: ${JSON.stringify(env)}`);
// reusable config for both server and preview
const serverConfig = {
host: true,
port: Number(env.VITE_PORT),
strictPort: true,
};
return {
base: '/',
plugins: [react()],
preview: serverConfig,
server: serverConfig,
};
});
© 2022 - 2024 — McMap. All rights reserved.