您需要向浏览器提供 importmap
,在 index.html
之前添加脚本类型 importmap
importmap
<!DOCTYPE html>
<html>
<head>
<title>Discoverthreejs.com - Your First Scene</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<link
rel="icon"
href="https://discoverthreejs.com/favicon.ico"
type="image/x-icon"
/>
<link href="./styles/main.css" rel="stylesheet" type="text/css" />
<script type="importmap">
{
"imports": {
"three": "./node_modules/three/build/three.module.js"
}
}
</script>
<script type="module" src="./src/main.js"></script>
</head>
<body>
<h1>Discoverthreejs.com - Your First Scene</h1>
<div id="scene-container">
<!-- Our <canvas> will be inserted here -->
</div>
</body>
</html>