- build tool로 vite 사용
- 크롬 브라우저 기준
- 간단한 프로젝트 제작 시
0. 초기 설정
- vite를 사용하기 위해 node.js가 설치되어 있어야 한다. node -v로 확인할 수 있다.
- npm init -y를 실행하면 NPM은 Node.js 프로젝트를 실행하는 데 필요한 최소한의 정보를 포함하는 package.json을 생성한다. ( npm init -y 명령어는 Node.js 프로젝트를 빠르게 초기화하는 명령어 )
1. vite와 three 패키지를 설치한다.
2. package.json의 scripts 부분을 수정한다.
3. vite.config.js 파일을 추가한다.
import restart from 'vite-plugin-restart'
export default {
root: 'src/', // Sources files (typically where index.html is)
publicDir: '../static/', // Path from "root" to static assets (files that are served as they are)
server:
{
host: true, // Open to local network and display URL
open: !('SANDBOX_URL' in process.env || 'CODESANDBOX_HOST' in process.env) // Open if it's not a CodeSandbox
},
build:
{
outDir: '../dist', // Output in the dist/ folder
emptyOutDir: true, // Empty the folder first
sourcemap: true // Add sourcemap
},
plugins:
[
restart({ restart: [ '../static/**', ] }) // Restart server on static file change
],
}
4. src 폴더 내 html, css, js 파일을 만든다.
5. 각 파일을 수정한다.
html
- script type="module"로 설정해주는 것을 잊지 않는다.
css
- 전체 `margin`과 `padding`을 없애 브라우저에서 기본 설정된 여백을 없애준다.
- `overflow: hidden;`을 통해 스크롤을 없앤다.
- `.webgl` canvas의 위치를 고정하고 테두리를 없앤다.
javascript
6. npm run dev를 통해 실행하고 브라우저에서 확인한다.
다음 단계: https://be-at-peace.tistory.com/13
참고 자료: three.js journey 3강
'web graphics' 카테고리의 다른 글
Three.js에서 박스의 색깔과 크기 변형하기 (0) | 2025.05.18 |
---|---|
Three.js 프로젝트 가장 쉽게 시작하기: (2) 캔버스 다루기 (0) | 2024.06.18 |