Thursday 24 January 2019

Creating a private local library of components dependant on react and styled-components

Hi folks,So I have a project the following folders at the project root: -- common- private-- package.json- public-- package.json​private and public both represent self-contained applications. Both of the apps import standard js (ES6) functions and constants from the common directory via yarn workspaces in their respective package.json files: -"workspaces": ["../common"],As you can see, this goes up one level from the app root so are not under the npm packages in the package.json files and therefore are not compiled by webpack (don't need to be as they are standard ES6).This was fulfilling my needs until recently, when I realised my project would work better (DRY coding) if I were to move some react and styled-components dependant components common to both applications to the common directory. But, as mentioned above, they are not subject to compiling by webpack to I get an error when I tried to import them (doesn't recognise import styled from styled-components).What is the best way around this? Am I looking at having to compile that directory separately via their own webpack compiler config then import them from there or is there a simpler way to do it? Thanks.

Submitted January 24, 2019 at 10:33PM by U4-EA

No comments:

Post a Comment