sveltekit에서 prod build 및 node로 실행하기
케이 (3)2022년 6월 01일
Tags #svelte#sveltekit

image

npm init svelte <app> 으로 설치한 환경입니다.

build된 js파일을 통해 node로 실행시키고 싶지만 build 디렉토리가 생성되지 않아 package.json을 살펴보았습니다.

package.json

{
	"scripts": {
		"dev": "svelte-kit dev --port 8080 --host",
		"build": "svelte-kit build",
		"package": "svelte-kit package",
		"preview": "svelte-kit preview --port 8080 --host",
		"prepare": "svelte-kit sync",
		"test": "playwright test",
		"check": "svelte-check --tsconfig ./tsconfig.json",
		"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
		"lint": "prettier --check --plugin-search-dir=. .",
		"format": "prettier --write --plugin-search-dir=. ."
	},
}

build가 있으니 일단 build를 해도 딱히 빌드 디렉토리가 생기지 않습니다.

조금 확인해보니 이 경우에는 svelte.config.json의 adapter를 만져줘야 원하는대로 동작합니다.

import adapter from '@sveltejs/adapter-node'
import preprocess from 'svelte-preprocess'

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://github.com/sveltejs/svelte-preprocess
	// for more information about preprocessors
	preprocess: preprocess(),

	kit: {
		//adapter: adapter(),
		adapter: adapter({ out: 'build' }),

		// Override http methods in the Todo forms
		methodOverride: {
			allowed: ['PATCH', 'DELETE']
		}
	}
}

export default config

config.kit.adapter를 수정해야 합니다. 기본값은 adapter-auto를 import하는 adapter를 넣는 것이었는데요.

adapter-node를 설치하고 kit.adapter에 adapter({out: 'build'}) 를 넣어줍니다.

이렇게 하면 build 디렉토리가 생성되고 node build/index.js로 앱 실행이 가능해집니다.


0개의 댓글