abhijithvijayan / web-extension-starter

🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension
MIT License
1.97k stars 169 forks source link

How to import jsx file in ContentScript? #71

Closed linonetwo closed 3 years ago

linonetwo commented 3 years ago

I get

ERROR in ./src/ContentScript/index.ts
Module not found: Error: Can't resolve './FloatingPanel' in 'xxxxx/ContentScript'
截屏2021-06-25 下午8 48 40

/ContentScript/index.ts

import './FloatingPanel';

export {};

/ContentScript/FloatingPanel/index.jsx

import * as React from 'react';
import ReactDOM from 'react-dom';

function FloatingPanel() {
  return <div>aaaa</div>;
}

const mountPointID = 'gamification-floating-ui-root';
document.body.insertAdjacentHTML('afterend', `<div id="${mountPointID}" />`);
ReactDOM.render(<FloatingPanel />, document.querySelector(`#${mountPointID}`));

This will not work.

So, How to render a React widget right into the webpage?

abhijithvijayan commented 3 years ago

i will investigate this soon

linonetwo commented 3 years ago

I guess that is why you export {}; in the index.ts

Oh, I tried out, but after I add export {}; to index.tsx it still can't be resolved...

abhijithvijayan commented 3 years ago

You are using react-javascript branch I presume

abhijithvijayan commented 3 years ago

I will check it out later.

linonetwo commented 3 years ago

Oh, wow, you point out the thing, it should be named index.tsx

Actually I'm using React + TypeScript branch, so this solves my problem, than you for this quick help!

linonetwo commented 3 years ago

This starter works pretty great, thank you for making this. I've followed you in Github now.

abhijithvijayan commented 3 years ago

Cool. Glad to know repo helped.