{"id":26981,"date":"2024-11-24T15:29:06","date_gmt":"2024-11-24T07:29:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26981\/"},"modified":"2024-11-24T15:29:06","modified_gmt":"2024-11-24T07:29:06","slug":"%e9%80%9a%e8%bf%87-unpkg-%e5%bc%95%e5%85%a5-three-js-%e5%90%8e%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e5%9c%a8-main-js-%e4%b8%ad%e6%97%a0%e6%b3%95%e8%af%86%e5%88%ab-three-%e5%af%b9%e8%b1%a1%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26981\/","title":{"rendered":"\u901a\u8fc7 unpkg \u5f15\u5165 three.js \u540e\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u5bf9\u8c61\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173114085055764.jpg\" class=\"aligncenter\" title=\"\u901a\u8fc7 unpkg \u5f15\u5165 three.js \u540e\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u5bf9\u8c61\uff1f\u63d2\u56fe\" alt=\"\u901a\u8fc7 unpkg \u5f15\u5165 three.js \u540e\uff0c\u4e3a\u4ec0\u4e48\u5728 main.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u5bf9\u8c61\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7 unpkg \u5f15\u5165 three.js<\/strong><\/p>\n<p>three.js \u65b0\u624b\u5e38\u5e38\u9047\u5230\u901a\u8fc7 unpkg CDN \u5f15\u5165 three.js \u65f6\uff0c\u65e0\u6cd5\u8bc6\u522b THREE \u5bf9\u8c61\u7684\u56f0\u6270\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u8ba9\u4f60\u987a\u5229\u4e0a\u624b three.js\u3002<\/p>\n<p>\u5728 index.html \u4e2d\uff0c\u53c2\u8003\u5b98\u7f51\u63a8\u8350\u7684 Option 2\uff0c\u4f7f\u7528 es-module-shims \u5e76\u5b9a\u4e49 importmap \u6765\u5f15\u5165 three.js\uff1a<\/p>\n<pre>&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<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u800c\uff0c\u5f53\u4f60\u5c06\u4ee3\u7801\u8f6c\u79fb\u5230\u4e1a\u52a1\u4ee3\u7801\u6a21\u5757 mn.js \u65f6\uff0c\u53ef\u80fd\u4f1a\u53d1\u73b0\u65e0\u6cd5\u8bc6\u522b THREE\u3002\u8fd9\u662f\u56e0\u4e3a main.js \u8fd8\u6ca1\u6709\u5b9a\u4e49 import \u8bed\u53e5\u3002<\/p>\n<p>\u4ee5\u4e0b\u6709\u4e24\u79cd\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\u5728 index.html \u7684 type=&#8221;module&#8221; \u811a\u672c\u6807\u7b7e\u4e2d\u76f4\u63a5\u7f16\u5199\u4e1a\u52a1\u4ee3\u7801\uff0c\u65e0\u9700\u989d\u5916\u7684 main.js \u6587\u4ef6\u3002<\/li>\n<li>\u5728 index.html \u4e2d\u4f7f\u7528 type=&#8221;module&#8221; \u7684 script \u6807\u7b7e\u5bfc\u5165 main.js\uff1a<\/li>\n<\/ol>\n<pre>&lt;script type=\"module\" src=\".\/main.js\"&gt;&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\u5728 main.js \u4e2d\u6dfb\u52a0 import \u5bfc\u5165\u8bed\u53e5\uff1a<\/p>\n<pre>import * as THREE from 'three';\n\nconsole.log(\"Hello Three.js\");\nconsole.log(\"js\" + THREE);\nconst scene = new THREE.Scene();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\u4e00\u6765\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728 main.js \u4e2d\u8bbf\u95ee THREE \u5bf9\u8c61\uff0c\u5e76\u521b\u5efa\u4e09\u7ef4\u573a\u666f\u3002\u968f\u7740 you \u6dfb\u52a0\u66f4\u591a\u4ee3\u7801 module types cript \u4e0d\u65ad\u7814\u7a76 three.js \u7684\u4e16\u754c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u901a\u8fc7 unpkg \u5f15\u5165 three.js \u540e\uff0c\u5728 mn.js \u4e2d\u65e0\u6cd5\u8bc6\u522b THREE \u5bf9\u8c61\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7 unpkg \u5f15\u5165 three.js three.js \u65b0\u624b\u5e38\u5e38\u9047\u5230\u901a\u8fc7 unpkg CDN \u5f15\u5165 three.js \u65f6\uff0c\u65e0\u6cd5\u8bc6\u522b THREE \u5bf9\u8c61\u7684\u56f0\u6270\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u8ba9\u4f60\u987a\u5229\u4e0a\u624b three.js\u3002 \u5728 index.html \u4e2d\uff0c\u53c2\u8003\u5b98\u7f51\u63a8\u8350\u7684 Option 2\uff0c\u4f7f\u7528 es-module-shims \u5e76\u5b9a\u4e49 importmap \u6765\u5f15\u5165 three.js\uff1a &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; \u767b\u5f55\u540e\u590d\u5236 \u7136\u800c\uff0c\u5f53\u4f60\u5c06\u4ee3\u7801\u8f6c\u79fb\u5230\u4e1a\u52a1\u4ee3\u7801\u6a21\u5757 mn.js \u65f6\uff0c\u53ef\u80fd\u4f1a\u53d1\u73b0\u65e0\u6cd5\u8bc6\u522b THREE\u3002\u8fd9\u662f\u56e0\u4e3a main.js \u8fd8\u6ca1\u6709\u5b9a\u4e49 import [&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-26981","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26981","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=26981"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26981\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}