admin管理员组

文章数量:1391969

I'm currently authoring a React project as well as an npm package that will be used by this project. My use-case of integrating the two includes providing a path to a React component in this project (e.g src/components/Comp1/Comp1_1.tsx) and for the npm package to resolve that path and import that component.

Is that something that's possible? Or do npm packages can't have context of the modules/files you have authored in your project folder?

So if i have a React component residing in src/components/Comp1/Comp1_1.tsx, i want my npm package to import it and return a new component based on it.

E.g, in my React project:

import plugin from 'my-library';

return (
   <plugin path="src/components/Comp1/Comp1_1.tsx" />
)

Then, the implementation of plugin is as follows:


const Comp1_1 = `React.lazy(() => import(${path})`  
return (
  <div>
    <Comp1_1 />
  </div>
)

Would that be possible for plugin to resolve that Comp1_1 import?

本文标签: