How should I use export and import in chrome extensions? I'm able to get dynamic imports to load the file, but how should I export?
I have a scripts directory that contains my scripts. The main content script is called content.js. I have allowed access to the other scripts (content_utils.js).
"content_scripts": [
{
"js": [
"scripts/content.js",
"scripts/content_utils.js"
],
"matches": [
"<all_urls>"
]
}
],
"web_accessible_resources": [{
"resources": ["scripts/*", "scripts/*/*"],
"matches": ["<all_urls>"]
}]
// content.js is two lines, import another file and run a function from the file
import(chrome.runtime.getURL('scripts/content_utils.js')) // no errors
echo("something"); // Uncaught ReferenceError: echo is not defined
// content_utils.js - Just an echo function
console.log("Utils loaded!") // This gets logged
function echo(value) {
console.log(`echo being called ${value}`)
return value;
}
export default { echo }; // Uncaught SyntaxError: Unexpected token 'export'