{"id":53144,"date":"2024-12-03T16:29:33","date_gmt":"2024-12-03T08:29:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53144\/"},"modified":"2024-12-03T16:29:33","modified_gmt":"2024-12-03T08:29:33","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e4%b8%8d%e4%bd%bf%e7%94%a8%e6%a1%86%e6%9e%b6%e7%9a%84%e6%83%85%e5%86%b5%e4%b8%8b%ef%bc%8c%e9%80%9a%e8%bf%87-unpkg-%e5%bc%95%e5%85%a5-three-js-%e5%b9%b6%e8%a7%a3%e5%86%b3-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53144\/","title":{"rendered":"\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7 unpkg \u5f15\u5165 Three.js \u5e76\u89e3\u51b3 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u7684\u95ee\u9898\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7 unpkg \u5f15\u5165 Three.js \u5e76\u89e3\u51b3 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u7684\u95ee\u9898\uff1f <\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7 unpkg \u5f15\u5165 Three.js \u5e76\u89e3\u51b3 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u7684\u95ee\u9898\uff1f \u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/17326859736746b0952fba5.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7 unpkg \u5f15\u5165 Three.js \u5e76\u89e3\u51b3 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u7684\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7 unpkg \u5f15\u5165 Three.js \u5e76\u89e3\u51b3 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u7684\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7unpkg\u5f15\u5165three.js\u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u95ee\u9898\u63cf\u8ff0\uff1a\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\u901a\u8fc7unpkg\u5f15\u5165three.js\uff1f<\/p>\n<p>\u76f8\u5173\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;!-- index.html --&gt;\n&lt;script async src=\"https:\/\/unpkg.com\/es-module-shims@1.6.3\/dist\/es-module-shims.js\"&gt;&lt;\/script&gt;\n&lt;script type=\"importmap\"&gt;\n  {\n    \"imports\": {\n      \"three\": \"https:\/\/unpkg.com\/three@0.155.0\/build\/three.module.js\"\n    }\n  }\n&lt;\/script&gt;\n&lt;script type=\"module\"&gt;\n  import * as THREE from 'three';\n  console.log(THREE);\n&lt;\/script&gt;<\/pre>\n<pre>\/\/ main.js\nconsole.log(\"Hello Three.js\")\nconsole.log(\"js\" + THREE)\nconst scene = new THREE.Scene();<\/pre>\n<p>\u95ee\u9898\u73b0\u8c61\uff1a<\/p>\n<p>\u5728main.js\u4e2d\u65e0\u6cd5\u8bc6\u522bTHREE\uff0c\u62a5\u9519\uff1a&#8221;main.js:2 Uncaught ReferenceError: THREE is not defined at main.js:2:20&#8243;<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>\u6709\u4e24\u79cd\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6848\u4e00\uff1a<\/strong><\/p>\n<p>\u5c06main.js\u7684\u7c7b\u578b\u6539\u4e3amodule\u5e76\u76f4\u63a5\u5728\u5176\u4e2d\u4e66\u5199\u4ee3\u7801\u3002<\/p>\n<pre>&lt;!-- index.html --&gt;\n&lt;script type=\"module\"&gt;\n  import * as THREE from 'three';\n  console.log(THREE);\n  console.log(\"Hello Three.js\");\n  console.log(\"js\" + THREE);\n  const scene = new THREE.Scene();\n&lt;\/script&gt;<\/pre>\n<p><strong>\u65b9\u6848\u4e8c\uff1a<\/strong><\/p>\n<p>\u5c06main.js\u4e2d\u7684\u4ee3\u7801\u79fb\u81f3index.html\u4e2d\uff0c\u5e76\u5c06main.js\u7684\u7c7b\u578b\u6539\u4e3amodule\u3002<\/p>\n<pre>&lt;!-- index.html --&gt;\n&lt;script type=\"module\"&gt;\n  import * as THREE from 'three';\n\n  console.log(\"Hello Three.js\");\n  console.log(\"js\" + THREE);\n  const scene = new THREE.Scene();\n&lt;\/script&gt;\n&lt;script type=\"module\" src=\".\/main.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7 unpkg \u5f15\u5165 Three.js \u5e76\u89e3\u51b3 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u7684\u95ee\u9898\uff1f \u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u8f7b\u677e\u5728\u7535\u8111\u4e0a\u540c\u65f6\u767b\u5f55\u4e24\u4e2a\u5fae\u4fe1\u8d26\u53f7\u7684\u5b8c\u6574\u6307\u5357\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7 unpkg \u5f15\u5165 Three.js \u5e76\u89e3\u51b3 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u7684\u95ee\u9898\uff1f \u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7 unpkg \u5f15\u5165 Three.js \u5e76\u89e3\u51b3 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u7684\u95ee\u9898\uff1f \u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01 \u901a\u8fc7unpkg\u5f15\u5165three.js\u7684\u89e3\u51b3\u65b9\u6848 \u95ee\u9898\u63cf\u8ff0\uff1a\u5982\u4f55\u5728\u4e0d\u4f7f\u7528\u6846\u67b6\u7684\u60c5\u51b5\u4e0b\u901a\u8fc7unpkg\u5f15\u5165three.js\uff1f \u76f8\u5173\u4ee3\u7801\uff1a &lt;!&#8211; index.html &#8211;&gt; &lt;script async src=&#8221;https:\/\/unpkg.com\/es-module-shims@1.6.3\/dist\/es-module-shims.js&#8221;&gt;&lt;\/script&gt; &lt;script type=&#8221;importmap&#8221;&gt; { &#8220;imports&#8221;: { &#8220;three&#8221;: &#8220;https:\/\/unpkg.com\/three@0.155.0\/build\/three.module.js&#8221; } } &lt;\/script&gt; &lt;script type=&#8221;module&#8221;&gt; import * as THREE from &#8216;three&#8217;; console.log(THREE); &lt;\/script&gt; \/\/ main.js console.log(&#8220;Hello Three.js&#8221;) console.log(&#8220;js&#8221; + THREE) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-53144","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53144"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53144\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}