簡體   English   中英

結合使用Chrome存儲API和create-react-app構建

[英]Using chrome storage API with create-react-app build

我正在創建一個Chrome擴展程序,並使用create-react-app引導了該項目。

一般問題:

我想在我的應用程序中訪問chrome.storage api

具體問題:

我希望能夠在我的React App中使用chrome.storage API來存儲一些設置,因此我在src目錄中創建了一個腳本,該腳本嘗試調用chrome.storage.sync.set()'chrome' is not defined no-undef 我認為這是因為我需要在清單中包含進行此調用的腳本。 問題是我無法在清單中包含src中的此腳本,因為在create-react-app構建我的項目后, src縮小了,文件結構也全部更改了。

另一個問題是create-react-app強制我僅從src導入,但我需要來自public數據,所以我不能只是通過從public導入函數來進行chrome API調用。 我知道create-react-app上有彈出功能,但我想維護create-react-app給我的構建功能。

從我的src目錄訪問chrome.storage API時,如何維護create-react-app的構建功能?

該錯誤( 'chrome is not defined no-undef' )看起來像是毛發錯誤; create-react-app附帶的linter認為chrome未定義,因為您的代碼從未定義它。 對於Linux擴展程序,linter鮮為人知,它是一個全局變量,因此不必定義它。

嘗試將/* global chrome */到使用chrome變量的文件頂部。

暫無
暫無

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

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