Unable to import SVG with Vite as ReactComponent

Update October 2023 – vite-plugin-svgr version ^4.0.0 When importing your SVG file using vite-plugin-svgr (see below), make sure to use the newly added ?react query suffix on your imported file, which allows you to use the default export and skip the ReactComponent aliasing: import ReactLogo from ‘./assets/react.svg?react’ <ReactLogo /> If you’re using TypeScript, you’ll also … Read more

How can I display the current app version from package.json to the user using Vite?

For React & TypeScript users: Add a define to your vite.config.ts: import react from ‘@vitejs/plugin-react’; import { defineConfig } from ‘vite’; export default defineConfig({ plugins: [react()], define: { APP_VERSION: JSON.stringify(process.env.npm_package_version), }, }); If you haven’t got one already, define a vite-env.d.ts or env.d.ts and add a declare: declare const APP_VERSION: string; You’ll now be able … Read more

vite build always using static paths

This leading path is the base URL, configured by the base option, which is / by default. You can remove the base URL by setting base to an empty string, making the path relative to its deployment directory: // vite.config.js import { defineConfig } from ‘vite’ export default defineConfig({ base: ”, 👈 }) demo

pnpm peer dependencies auto-install

pnpm uses npm’s configuration formats. Hence, you should set configuration the same way you would for npm: pnpm config set auto-install-peers true Note: The above command uses the default config location which stores the setting for the local user account (at ~/.npmrc for linux, or at %USERPROFILE%\.npmrc for Windows). To store the setting inside your … Read more