svelte kit 폴더 구조 및 설정

sting01·2023년 4월 13일

sveltekit

목록 보기
1/9

프로젝트 구조

static - 정적인 요소들

  • image
  • video
  • audio
  • fonts
  • favicon

src - 핵심 폴더

  • lib
    1. componets

    1. css/scss
    2. utils
    3. imges
    4. server
    5. store
  • api

  • params

  • routes => 라우팅을 담당하는 폴더 *중요
    1. 라우팅 역할

    1. +layout.svelte.
    2. +layout.server.ts,js
    3. +page.svelte
    4. +page.ts,js
    5. /api/ -> 페이지에서 처리하는 api 관련 역할 분리 처리
  • app.js

  • app.html

  • .env -> key 값 저장

    API_KEY = secret key;
    PUBLIC_KEY = public key;
  • app.d.ts -> 지정 타입 관련 분리 처리 가능

    	```

    // See https://kit.svelte.dev/docs/types#app
    // for information about these interfaces
    declare global {
    namespace App {
    interface Error {
    message?: string;
    code?: string;
    }
    interface Locals {
    user?: {
    id: number;
    name: string;
    };
    }
    // interface PageData {
    // products?: { id: number }[];
    // }
    // interface Platform {}
    }
    }

    export {};

vscode

svelte.config.js

import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://kit.svelte.dev/docs/integrations#preprocessors
	// for more information about preprocessors
	preprocess: vitePreprocess(),
    preprocess: preprocess(
		{
			scss: {
				prependData: '@use "./src/lib/scss/functions";  @use "@unsass/breakpoint";'
			}
		}
	),


	kit: {
		// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
		// If your environment is not supported or you settled on a specific environment, switch out the adapter.
		// See https://kit.svelte.dev/docs/adapters for more information about adapters.
		adapter: adapter(),
		// files: {
		// 	routes: './src/pages'
		// }
		alias: {$components: 'src/lib/components'},
		prerender: {
			crawl: true,
			entries: ['*']
		}
	},
};

export default config;

postcss.config.js

export default {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

tailwind.config.js

/** @type {import('tailwindcss').Config} */
export default {
  content: ['./src/**/*.{html,js,svelte,ts}'],
  theme: {
    extend: {},
  },
  plugins: [],
}

vite.config.ts

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

export default defineConfig({
	plugins: [sveltekit()],
	test: {
		include: ['src/**/*.{test,spec}.{js,ts}']
	}
});

vscode 익스 텐션 스벨트 관련

https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode
https://marketplace.visualstudio.com/items?itemName=ardenivanov.svelte-intellisense
https://marketplace.visualstudio.com/items?itemName=fivethree.vscode-svelte-snippets
https://marketplace.visualstudio.com/items?itemName=fivethree.vscode-svelte-snippets
https://marketplace.visualstudio.com/items?itemName=RafaelMartinez.svelte-preview

1개의 댓글

comment-user-thumbnail
2023년 12월 17일

스벨트 폴더구조 찾다가 좋은 참고 하고 갑니다~!~!

답글 달기