How to rollup .native files in a library shared by React and React Native

38 Views Asked by At

Given I have something like the following:

// src/helloWorld.native.ts
export const helloWorld = (): string => {
  return "hello from Mobile";
};


// src/helloWorld.ts
export const helloWorld = (): string => {
  return "hello from Web";
};

I have an index.ts that simply exports helloWorld from

export * from "./src/helloWorld";

The problem is, I don't know how to roll this up to keep the .native. I believe this is how the platform-specific code should work in RN, but I don't know how to get it to rollup properly to keep the .native files. When I roll it up it only keeps src/helloWorld, I believe because that's all that's getting traversed from index.ts. Is there a good way to do this?

My rollup config is very basic (I'm new to rollup and used the most basic config I could)

import typescript from "@rollup/plugin-typescript";

export default [
  {
    input: ["./index.ts"],
    output: {
      dir: "dist",
      format: "esm",
      preserveModules: true,
      sourcemap: true,
    },
    treeshake: false,
    plugins: [
      typescript({
        include: ["**/*.ts", "**/*.js"],
        tsconfig: "./tsconfig.json",
      }),
    ],
  },
];

I rolled up a basic hello world module but can not get it to keep the .native extension files

0

There are 0 best solutions below