簡體   English   中英

我可以從 CDN 制作 Reason+React 導入反應模塊嗎?

[英]Can I make Reason+React import react module from CDN?

使用 Reason 和 React 構建組件總是會給我一個“react”的模塊導入語句,如果 React 包含在 CDN 中,則無法找到該語句。 有解決方案嗎? 我試圖在 index.html 中定義window.react = React沒有成功。 es6-global設置不會改變任何東西。

我沒有使用像 webpack 這樣的捆綁程序。

編輯:可能來自 Reason 論壇的相關主題: https : //reasonml.chat/t/can-one-load-reasonml-es6-modules-without-a-bundler/2219

類似問題(未解決): 可以在沒有打包器的情況下加載 reasonml es6 模塊嗎

importmap (尚未在瀏覽器中實現)可能是另一個解決方案: 使用沒有 Transpiler/Bundler 步驟的 ES6 模塊

從技術上講,是的,你可以,但它不會像使用 npm 流和使用捆綁器那么容易。

ReasonReact 綁定的編寫方式可以生成導入模塊的輸出 JavaScript,例如:

import * as React from "react";

(如果使用 ES6 模塊樣式。)

如果使用 CDN,您可能需要如下所示的輸出:

import * as React from "https://some.cdn/react";

控制輸出 JS 的語法(來自ReasonReact repo )是:

[@bs.module "react"]
external createElement: (component('props), 'props) => element = "createElement";

如果您將其更改為:

[@bs.module "https://some.cdn/react"]
external createElement: (component('props), 'props) => element = "createElement";

...然后你會得到所需的輸出。 但問題是您需要更改源……即為該 CDN 維護或查找 React 的分叉綁定。 或者設置一些代碼自動化,用[@bs.module "https://some.cnd/react"]查找和替換[@bs.module "react"] [@bs.module "https://some.cnd/react"] 所以無論哪種方式,它都不像使用捆綁器那么簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM