create-react-app を使用するprocess.env.REACT_APP_VERSIONと、これに使用できます。
Viteに同等のものはありますか?
create-react-app を使用するprocess.env.REACT_APP_VERSIONと、これに使用できます。
Viteに同等のものはありますか?
defineに aを追加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),
},
});
まだ取得していない場合は、 a を定義して aglobal.d.tsを追加しdeclareます。
declare const APP_VERSION: string;
コード内のどこでも変数を使用できるようになり、APP_VERSIONVite はコンパイル時にそれを置き換えます。
注: Intellisense が宣言を取得するには、TS サーバーを再起動する必要がある場合があります。
VSCode MacOS:⌘</kbd> + ⇧</kbd> + P > Restart TS Server
VSCode Windows: ctrl+⇧</kbd> + P > Restart TS Server