0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PWA reactプロジェクト立ち上げ

Last updated at Posted at 2025-05-16

 

プロジェクト立ち上げ&プラグインインストール

作りたいフォルダで下記コマンドでプロジェクト立ち上げ&プラグインインストール

npm create vite@latest プロジェクト名 -- --template react
cd プロジェクト名
npm install
npm install vite-plugin-pwa --save-dev

 

プロジェクト直下にvite.config.jsが作られているはずなので中身を以下に変えて保存する

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { VitePWA } from 'vite-plugin-pwa';

export default defineConfig({
  server: {
    host: true  // ← これがないと外部からアクセスできない!
  },
  plugins: [
    react(),
    VitePWA({
      registerType: 'autoUpdate',
      includeAssets: ['favicon.svg'],
      manifest: {
        name: 'My PWA App',
        short_name: 'PWA App',
        start_url: '/',
        display: 'standalone',
        background_color: '#ffffff',
        theme_color: '#317EFB',
        icons: [
          {
            src: 'pwa-icon-192.png',
            sizes: '192x192',
            type: 'image/png'
          },
          {
            src: 'pwa-icon-512.png',
            sizes: '512x512',
            type: 'image/png'
          }
        ]
      }
    })
  ]
});

仮想サーバー立上げ&iPhoneからPWA実感

npm run build
npm run preview

npm run previewでPWAを実装するための仮想サーバーが立ち上がる。
画像のようなURLが出ていればOK
 
スクリーンショット 2025-05-16 13.17.40.png

Networkに書かれたURLをiPhoneのSafariなどで検索すると
アプリで内容を確認できる。

)

あとはホーム画面に出す手順
1、共有(下のタブの真ん中)
2、ホーム画面に追加

でPWA完了

もしIPアドレスがわからなかったら

ipconfig getifaddr en0

IPが出るので
http://IPアドレス/4173
でiPhoneからアクセスする。

4173の部分は仮想サーバー立ち上げ時に出ているので違う場合はかえる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?