Closed avi12 closed 1 year ago
Maybe I didn’t quite understand the problem, but why not put the reusable functions into separate modules and import them in background/index.ts
and in some files, like storage.ts
https://github.com/NekitCorp/chrome-extension-svelte-typescript-boilerplate/blob/main/src/background/index.ts?
The thing is that this line expects a fixed path So I was wondering, is there a way that I could have a predetermined path to a file?
Yes, you can:
import
src/background/index.ts
:
import data from "../data.json";
chrome.runtime.onInstalled.addListener(() => {
console.log(data);
});
Create public
folder in root project directory, and create data.json
inside public
folder.
src/background/index.ts
:
chrome.runtime.onInstalled.addListener(() => {
const url = chrome.runtime.getURL("data.json");
fetch(url)
.then((res) => res.json())
.then(console.log);
});
the result is the same as in option 1
Output:
I wish to add some files that interface directly with
background/index.ts
, however they're not supposed to be imported Is it possible in this boilerplate?