break-stuff / cem-tools

Tooling for generating features based on the Custom Elements Manifest
MIT License
95 stars 11 forks source link

Bug: Treeshaking not wroking #146

Open venkatesh-nagineni opened 1 month ago

venkatesh-nagineni commented 1 month ago

I am testing react wrapper with my stencil components where i have generated components like this

import { generateReactWrappers } from "custom-element-react-wrappers";
import manifest from "../custom-data/custom-elements.json" assert { type: "json" };

generateReactWrappers(manifest,
    {
        outdir: 'wrappers/react/dist/',
        modulePath: (className, tagName) => `@lib/my-components/dist/components/${tagName}.js`,
        defaultExport: true,
    });

and in my stencil config have dist custom elements like

        {
            type: 'dist-custom-elements',
            externalRuntime: false, // https://github.com/ionic-team/stencil/issues/5596#issuecomment-2058481138
        },

in react project, i am using only button component but when browser render all my components

does anything wrong i am doing here or it's something we need to take care Screenshot 2024-07-18 at 15 18 29 Screenshot 2024-07-18 at 15 18 52

break-stuff commented 1 month ago

The index.js file exports all of the components. When you do your final build, only the used modules should be included in the final output. If that doesn't work, you can always import the components individually:

import { Button } from 'path/to/react/Button.js';
import { Dialog } from 'path/to/react/Dialog.js';

Instead of:

import { Button, Dialog } from 'path/to/react';