Open2

Astroメモ📝

つづこつづこ

命名(慣習)

  • page/*.astro ファイルは kebab-case(URLに反映される)
  • src/components/ 内のコンポーネント名は PascalCase
つづこつづこ

パスエイリアスを使う👀

  1. tsconfig.json にパスの設定
    tsconfig.json
    {
      "compilerOptions": {
        "baseUrl": ".", 
        "paths": {
          "@/*": ["src/*"]
        }
      }
    }
    
  2. astro.config.mjs に Vite用 のエイリアスも追加
    astro.config.mjs
    import { defineConfig } from 'astro/config';
    
    export default defineConfig({
      vite: {
        resolve: {
          alias: {
            '@': new URL('./src', import.meta.url).pathname,
          }
        }
      }
    });