antwarjs / antwar

A static site generator built with React and Webpack.
https://antwar.js.org/
MIT License
460 stars 35 forks source link

Antwar Interactive ID Resolving Bug #134

Open skipjack opened 6 years ago

skipjack commented 6 years ago

Importing a component directly from an npm package, and using it as an interactive component with an ID of the same path throws build errors. For example:

import VoteApp from 'webpack.vote'

// ...
<Interactive
     id="webpack.vote" // or "webpack.vote/dist/vote.bundle.js"
     component={ VoteApp } />

I did find a workaround by specifying the full relative path:

id="./node_modules/webpack.vote"

Admittedly, this probably won't happen too often so if it's a complex or hacky fix maybe a better approach is just to document the workaround.

bebraw commented 6 years ago

I think I finally figured out a nice way to solve this. We can write a Babel plugin that can inject Interactive with the correct id (path). Then you would simply do <VoteApp /> and the plugin would detect when to wrap (based on state and/or handlers).