Conflicting issues compiling code in Rollup / Typescript / React

Viewed 102

I got a job back in August, and most importantly through this pandemic, I've actually kept it too!!

As a side project I wanted to learn to create a react component library for my own use (far from complete) with Rollup for it's tree-shaking + plugins for cjs, udm, etc. for compatability.

When I compile with TSC it's almost perfect now that I've tweaked a couple of things regarding organization and a separate build TSConfig.

My TSConfig

My Build TSConfig

My Rollup Config

I'm not sure if there's any glaring issues that anyone can see at first glance or not, I've tweaked a bit here and there trying to get rollup to even work in teh first place, but it's obviously not resolving correctly otherwise I wouldn't be here! :D

Side note: Despite setting up a custom.d.ts in the root for declaring svg imports with svgr, TS still isn't understanding the declaration and throws a type error:

declare module '*.svg' {
import React = require('react')
export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>
const src: string
export default src
}

I say TSC Config is almost perfect, but there's a few things I'm aware of:

  1. I'm not sure that TSC compiling is good for Tree-shaking. Correctly me if I'm wrong here, but that's why Rollup is a thing, right?
  2. TSC doesn't seem to transforming my path aliases within the config, where I have '@app' for 'src' to beat the '../../../../' resolving.

When I try to use Rollup I come into two different issues entirely:

  1. Despite having the types in a folder ./src/types/*.ts I don't have a root level declaration file within my 'dist' folder, they're scattered amongst the individual component folders for their props.
  2. Not all props and types that are for sure utilized in exported components etc. are being exported, there are several components that are having (_a: any) are their props which is obviously a very back experience to work with.
  3. I'm not sure if it's resolving / transforming my path aliases either, so that's something I have to double check.

If anyone can aid in this issue I'd be eternally grateful! I've already searched through Google/Reddit/SO for anyone with similar issues as I can I haven't come across any solutions that have worked successfully.

0 Answers
Related