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?

More than 1 year has passed since last update.

Github+vite+amplify+react

Last updated at Posted at 2022-12-18

目的

忘れがちなので、GithubからすぐにCI/CDできるホスティング整備手順。
さくっとフロントの検証アプリを作りたい時に。

Githubでリポジトリ追加

git clone

vite create

pnpm create vite ./

reactを選んでプロジェクト基本構成作成。

vite.config.ts編集

base: "./",を追記。

vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  plugins: [react()]
})

Vite + Amplifyへの手当て

vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  plugins: [react()],
  define: {
    global: 'window',
  }
})

amplifyで対象レポジトリ追加

amplify.ymlのbaseDirectory修正

baseDirectory: /distへ変更。

image.png

manifest.webmanifestをpublic/に配置

manifest.webmanifest.json
{
  "$schema": "https://json.schemastore.org/web-manifest-combined.json",
  "name": "HackerWeb",
  "short_name": "HackerWeb",
  "start_url": ".",
  "display": "standalone",
  "background_color": "#fff",
  "description": "読みやすいハッカーニュースアプリです。",
  "icons": [
    {
      "src": "images/touch/homescreen48.png",
      "sizes": "48x48",
      "type": "image/png"
    },
    {
      "src": "images/touch/homescreen72.png",
      "sizes": "72x72",
      "type": "image/png"
    },
    {
      "src": "images/touch/homescreen96.png",
      "sizes": "96x96",
      "type": "image/png"
    },
    {
      "src": "images/touch/homescreen144.png",
      "sizes": "144x144",
      "type": "image/png"
    },
    {
      "src": "images/touch/homescreen168.png",
      "sizes": "168x168",
      "type": "image/png"
    },
    {
      "src": "images/touch/homescreen192.png",
      "sizes": "192x192",
      "type": "image/png"
    }
  ],
  "related_applications": [
    {
      "platform": "play",
      "url": "https://play.google.com/store/apps/details?id=cheeaun.hackerweb"
    }
  ]
}

pnpm

pnpm install \
@aws-amplify/ui-react \
@emotion/react \
@emotion/styled \
@fontsource/roboto \
@mui/icons-material \
@mui/material \
@mui/styled-engine-sc \
aws-amplify \
react \
react-dom \
styled-components

aws-exports.ts

aws-exports.jsをtsで扱うことになるが、aws-exports.tsは更新されず、aws-exports.jsが更新されるので、適宜マージする。

amplify.yml

version: 1
appRoot: './web'
frontend:
  phases:
    # IMPORTANT - Please verify your build commands
    build:
      commands: ['npm install --legacy-peer-deps', 'npm run build']
  artifacts:
    # IMPORTANT - Please verify your build output directory
    baseDirectory: './dist/'
    files:
      - '**/*'
  cache:
    paths: ['./web/node_modules']

/web/srcにソースを配置する場合、こんな感じ。
appRootを追加しているが、使い方間違っているかも。

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?