{"id":28167,"date":"2024-11-24T13:59:13","date_gmt":"2024-11-24T05:59:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28167\/"},"modified":"2024-11-24T13:59:13","modified_gmt":"2024-11-24T05:59:13","slug":"%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e5%9c%a8-html-%e4%b8%ad%e6%98%be%e5%bc%8f%e6%8c%82%e8%bd%bd-umd-%e6%96%b9%e6%b3%95%e5%88%b0-window-%e5%af%b9%e8%b1%a1%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28167\/","title":{"rendered":"\u5982\u4f55\u907f\u514d\u5728 HTML \u4e2d\u663e\u5f0f\u6302\u8f7d UMD \u65b9\u6cd5\u5230 window \u5bf9\u8c61\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173141696236260.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u907f\u514d\u5728 HTML \u4e2d\u663e\u5f0f\u6302\u8f7d UMD \u65b9\u6cd5\u5230 window \u5bf9\u8c61\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u907f\u514d\u5728 HTML \u4e2d\u663e\u5f0f\u6302\u8f7d UMD \u65b9\u6cd5\u5230 window \u5bf9\u8c61\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 html \u4e2d\u8c03\u7528 vite \u6253\u5305\u540e\u7684 umd \u65b9\u6cd5<\/strong><\/p>\n<p>\u5728 Vite \u4e2d\u6253\u5305 UMD \u6587\u4ef6\u540e\uff0c\u8981\u76f4\u63a5\u5728 HTML \u4e2d\u8c03\u7528\u5176\u66b4\u9732\u7684\u65b9\u6cd5\uff0c\u901a\u5e38\u9700\u8981\u5c06\u65b9\u6cd5\u6302\u8f7d\u5230 window \u5bf9\u8c61\u4e0a\u3002\u4f46\u662f\uff0c\u6709\u53e6\u4e00\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u6b64\u76ee\u7684\uff1a<\/p>\n<p>\u6253\u5305\u65f6\uff0c\u60a8\u53ef\u4ee5\u5728 Vite \u914d\u7f6e\u4e2d\u8bbe\u7f6e output.globals \u9009\u9879\uff0c\u5c06\u66b4\u9732\u7684\u65b9\u6cd5\u6620\u5c04\u5230\u5168\u5c40\u53d8\u91cf\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>build: {\n  lib: {\n    name,\n    fileName: name,\n    entry: path.resolve(__dirname, 'src\/main.ts')\n  },\n  rollupOptions: {\n    output: {\n      sourcemap: true,\n      globals: {\n        '.\/src\/main.ts': 'canvasEditorFun'\n      }\n    }\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6253\u5305\u540e\u7684 UMD \u6587\u4ef6\u5c06\u5305\u542b\u7c7b\u4f3c\u4ee5\u4e0b\u5185\u5bb9\u7684\u4ee3\u7801\uff1a<\/p>\n<pre>var canvasEditorFun = {...};\nwindow.canvasEditorFun = canvasEditorFun;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u5728 HTML \u4e2d\u4f7f\u7528 canvasEditorFun \u53d8\u91cf\u6765\u8c03\u7528\u66b4\u9732\u7684\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>&lt;script&gt;\n  canvasEditorFun.initEditorByFile(...);\n&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u91c7\u7528\u8fd9\u79cd\u65b9\u6cd5\uff0c\u60a8\u4e0d\u9700\u8981\u5c06\u65b9\u6cd5\u663e\u5f0f\u6302\u8f7d\u5230 window \u5bf9\u8c61\u4e0a\uff0c\u800c\u662f\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u5168\u5c40\u53d8\u91cf\u8bbf\u95ee\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u907f\u514d\u5728 HTML \u4e2d\u663e\u5f0f\u6302\u8f7d UMD \u65b9\u6cd5\u5230 window \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>\u5728 html \u4e2d\u8c03\u7528 vite \u6253\u5305\u540e\u7684 umd \u65b9\u6cd5 \u5728 Vite \u4e2d\u6253\u5305 UMD \u6587\u4ef6\u540e\uff0c\u8981\u76f4\u63a5\u5728 HTML \u4e2d\u8c03\u7528\u5176\u66b4\u9732\u7684\u65b9\u6cd5\uff0c\u901a\u5e38\u9700\u8981\u5c06\u65b9\u6cd5\u6302\u8f7d\u5230 window \u5bf9\u8c61\u4e0a\u3002\u4f46\u662f\uff0c\u6709\u53e6\u4e00\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u6b64\u76ee\u7684\uff1a \u6253\u5305\u65f6\uff0c\u60a8\u53ef\u4ee5\u5728 Vite \u914d\u7f6e\u4e2d\u8bbe\u7f6e output.globals \u9009\u9879\uff0c\u5c06\u66b4\u9732\u7684\u65b9\u6cd5\u6620\u5c04\u5230\u5168\u5c40\u53d8\u91cf\u3002\u4f8b\u5982\uff1a build: { lib: { name, fileName: name, entry: path.resolve(__dirname, &#8216;src\/main.ts&#8217;) }, rollupOptions: { output: { sourcemap: true, globals: { &#8216;.\/src\/main.ts&#8217;: &#8216;canvasEditorFun&#8217; } } } } \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6253\u5305\u540e\u7684 UMD \u6587\u4ef6\u5c06\u5305\u542b\u7c7b\u4f3c\u4ee5\u4e0b\u5185\u5bb9\u7684\u4ee3\u7801\uff1a var canvasEditorFun = {&#8230;}; window.canvasEditorFun [&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-28167","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28167","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=28167"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28167\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}