스벨트킷 sveltekit에서 tailwindcss와 daisyUi 사용하기

카테고리 없음|2022. 5. 10. 22:59
반응형

HTML 스타일을 할 때 tailwindcss를 사용하면 직접 css를 작성하는 것 보다 쉽고 자유롭게 스타일을 할 수 있다. 

https://tailwindcss.com/

 

그리고 이미 테일윈드를 통해 스타일이 만들어져 있는 daisyUi를 사용하게 된다면 예전에 부트스트랩을 사용하 듯. 쉽게 디자인을 만들어 낼 수 있다.

https://daisyui.com/

 

 

 

1. tailwindcss 설치

이 글에서는 스벨트킷에 적용하는 방법을 설명 하려고 한다.

 

스벨트킷을 스켈레톤으로 설치하고 실행하게 되면 아래의 화면을 볼 수 있을 것이다. 

스벨트킷에 tailwindcss를 설치하는 방법은 사실 아래의 주소에 아주 잘 나와있다.

https://tailwindcss.com/docs/guides/sveltekit

 

홈페이지를 따라 해보자

 

스벨트킷 기본파일들

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init tailwind.config.cjs -p
mv postcss.config.js postcss.config.cjs

 

npx tailwindcss init tailwind.config.cjs -p를 cmd에 입력을 하니 

tailwind.config.cjs파일과 postcss.config.js파일이생겼다

 

윈도우에 설치하는 것이기 때문에 

cmd에 mv postcss.config.js postcss.config.cjs 대신 move postcss.config.js postcss.config.cjs 를 치니 

postcss.config.js에서 postcss.config.cjs파일로 바뀌었다. (만일 실수로 postcss.config.js가 남아있게 되면 에러가 발생함)

 

tailwind.config.cjs에 아래와 같이 입력함

module.exports = {
  content: ['./src/**/*.{html,js,svelte,ts}'],
  theme: {
    extend: {}
  },
  plugins: []
};

 

./src/app.css 를 만든 뒤 아래를 입력함

@tailwind base;
@tailwind components;
@tailwind utilities;

./src/routes/__layout.svelte 를 만든뒤

<script>
  import "../app.css";
</script>

<slot />

 

이제 실행해보면 모든 기본 스타일이 없어지게 된다. 

이제 아래 처럼 테일윈드의 클래스를 입력해보자. 스타일이 적용이 되는 것을 볼 수 있다.

 

 

이렇게 tailwind를 설치를 완료했으면 다음으로 daiyUI를 설치해보자.

https://daisyui.com/docs/install/

 

공식문서를 그냥 따라하면 된다.

npm i daisyui

 

tailwind.config.js에 아래와 같이 추가함

module.exports = {
  //...
  plugins: [require("daisyui")],
}

 

이렇게 daisyUI를 설치하게 되었다. 

index.svelte에 daiyUI의 예제를 입력해 보앗다.

<div class="alert alert-info shadow-lg">
  <div>
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current flex-shrink-0 w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
    <span>New software update available.</span>
  </div>
</div>

 

결과:

 

반응형

댓글()

[SVELTEKIT] capacitor 사용하여 안드로이드 앱 만들기

Computer 관심/Svelte|2022. 2. 20. 00:40
반응형

아이오닉사용해서 sveltekit 안드로이드 앱만들기

 

이미 스벨트로 만들어 놓은 코드가 있어서, 굳이 플러터 flutter를 사용하지 않고 기존 코드를 이용하여 앱을 만들어 보고 싶었다. 처음 앱으로 빌드할 때 좀 느렸지만 이후엔 빠르게 빌드가 됬다. 

오래 사용해보지 않아 얼마나 좋은지 나쁜지는 잘 모르겠지만 가벼운앱을 만들땐 괜찮을 않을까 싶다.

 

 

1. 기존에 있던 프로젝트에 capacitor 설치하기

npm install @capacitor/core @capacitor/cli

 

2. capacitor init 하기

capacitor를 init할때 스벨트킷의 빌드할 폴더는 build이기 때문에 기본값 www대신 build로 적어 준다..

(혹시라도 init 때 www로 설정해놓더라도 capacitor.config.ts의 webDir에서 나중에 바꿀 수 있으니 걱정할 필요 없다.)

npx cap init

 

3. 안드로이드나 IOS 플랫폼 설치

npm i @capacitor/ios @capacitor/android
npx cap add android //안드로이드 추가
npx cap add ios //ios 추가

 

4. 싱글페이지 빌드용 어뎁터 설치하기

npm i -D @sveltejs/adapter-static

https://github.com/sveltejs/kit/tree/master/packages/adapter-static

 

5.  싱글페이지로 빌드하기 위해 svelte.config에 아래와 같은 코드를 넣어준다. 

import adapter from '@sveltejs/adapter-static';

 

아래 코드를 보듯 기존 import adapter from '@sveltejs/adapter-auto'; 를 대체하였다.

// import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-static';
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(
        {fallback: 'index.html'}
        )
	}
};

export default config;

6. routes/+layout.js 파일 만들고 

export const prerender = true

 

 

 

7. 스벨트 빌드하기

npm run build

 

 

 

8.실행시키기

//안드로이드 스튜디오에서 실행
npx cap open android 

//실기기 실행
npx cap run android

 

 

 

 

-----------------------------------------------------

 

 

라이브 리로드

1. capacitor.config.ts의 내용을 아래로 대체함

import { CapacitorConfig } from '@capacitor/cli';

const appId = '앱.아이.디';
const appName = '앱이름';
const server = process.argv.includes('-hmr') ? {
  'url': 'http://192.168.5.67:5173',   // always have http:// in url
  'cleartext': true
} : {};
console.log(server);
const webDir = 'build';

const config: CapacitorConfig = {
  appId,
  appName,
  webDir,
  server
};

if (process.argv.includes('-hmr')) console.log('WARNING: running capacitor with livereload config', config);

export default config;

 

2. svelte를 디버깅 모드로 실행

npm run dev -- --host //호스트를 넣어서 아이피를 오픈해줘야함

 

3. 실기기에서 실행

cmd창을 하나 더 열고 아래의 명령어를 입력함

npx cap run android

 

 

 

 

참조

https://capacitorjs.com/docs/cli

 

Capacitor: Cross-platform native runtime for web apps

Build iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript

capacitorjs.com

 

 

반응형

댓글()