簡體   English   中英

如何將javascript header添加到node.js建index.html

[英]How to add javascript header to node js built index.html

所以我正在嘗試將一個有效的 React 應用程序制作成一個 Twitch 擴展(我不需要任何 twitch 集成)。

讓它與 Twitch 的 iframe 一起工作的唯一方法是在 html 文件中添加一個標簽

<script src="https://extension-files.twitch.tv/helper/v1/twitch-ext.min.js"></script>

啟動時調用 javascript 代碼,使用 twitch-ext.min.js 文件中的內容

window.Twitch.ext.onAuthorized(function(auth) {
  console.log('The JWT that will be passed to the EBS is', auth.token);
  console.log('The channel ID is', auth.channelId);
});

我目前正在做的是運行npm 構建,然后手動編輯生成的 index.html 和 main.xxxxx.js 以將這些代碼行包含在優化的縮小文件中。 這顯然看起來有點低效,我覺得必須有一種方法告訴節點在構建期間它應該包括這些行。 那么我問的可能嗎?

所以我從了解 Node.js 的人那里得到了答案。 您要做的是編輯您的 React 應用程序應具有的 index.html 和 index.js 文件。

npm run build實際上使用這兩個文件來生成縮小的構建文件,所以我剛剛添加了

<script src="https://extension-files.twitch.tv/helper/v1/twitch-ext.min.js"></script>

到 index.htmla 和我的

window.Twitch.ext.onAuthorized()

調用 index.js 文件,一切正常。

如果你使用npx create-react-app ,你可以在你的反應項目的公共文件夾中找到 index.html 。 而 index.js 在 src 文件夾中。

暫無
暫無

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

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