5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS Amplify + Bun + Svelte のビルド設定

Last updated at Posted at 2024-11-08

TL;DR

Bun をインストールする:

curl -fsSL https://bun.sh/install | bash

Svelteのための gzimbron/amplify-adapter をインストールする:

bun install amplify-adapter

svelte.config.js のアダプターを変更する:

import adapter from 'amplify-adapter'; // ← コレ
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

              
/** @type {import('@sveltejs/kit').Config} */
const config = {
        preprocess: vitePreprocess(),

        kit: {
                adapter: adapter()
        }
};

export default config;

AWS Amplifyのビルド用YAMLファイルを、以下のように記述する:

version: 1
frontend:
  phases:
    preBuild:
      commands:
        # Bunをインストール
        - curl -fsSL https://bun.sh/install | bash
        - source /root/.bashrc
        - bun install
    build:
      commands:
        # Bunを用いて、Svelteのamplify-adapterを利用
        - bun run build
        - cd build/compute/default/
        - bun i --production
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

参考文献

AWS + Bun

上記イシューのコメントでは、以下のようなYAMLファイルが示されている:

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            # install bun
            - curl -fsSL https://bun.sh/install | bash
            - source /root/.bashrc
            - bun install
        build:
          commands:
            - bun run build
      artifacts:
        # IMPORTANT - Please verify your build output directory
        baseDirectory: dist
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    appRoot: client

同僚の @Kanahiro に教えてもらいました、感謝!

AWS + Svelte

上の記事では、以下のようなYAMLファイルが示されている( cd build/compute/default/ とあることに注意):

version: 1
frontend:
    phases:
        preBuild:
            commands:
                - 'npm ci --cache .npm --prefer-offline'
        build:
            commands:
                - 'npm run build'
                - 'cd build/compute/default/'
                - 'npm i --production'
              
    artifacts:
        baseDirectory: build
        files:
            - '**/*'
    cache:
        paths:
            - '.npm/**/*'

以下の記事も参考のこと:

5
1
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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?