react + Three.js 创建与部署

React 创建

链接:https://reactjs.org/docs/create-a-new-react-app.html

npx create-react-app my-app
cd my-app
yarn add three @react-three/drei @react-spring/three react-three-fiber sass
npm start

React-three-fiber

链接:https://github.com/pmndrs/react-three-fiber

npm install three @react-three/fiber

物理模块

链接:https://github.com/pmndrs/use-cannon

yarn add @react-three/cannon
import { Physics, useBox, ... } from '@react-three/cannon'

部署

部署时默认app放入网站根目录,如果要放在其他,位置需要修改app路径,在package.json文件中任意位置加入:

"homepage": "https://www.louisxu.com/build",