0

I've created an npm workspace with two packages "foo" and "bar".
Furthermore, I'm using typescript so both packages contain a src/index.ts.

During development, I want to have the "main" property of both packages to be src/index.ts.
But after building and publishing the packages the "main" entry has to point to the built dist/index.js.

How can I accomplish that or is my assumption wrong, that I can point to the typescript file during development?
But then I would have to rebuild the packages during development all the time.
I hope that's not necessary.

Thank you for your help in advance

UPDATE
To be more precise, I need to have "main" point to the Typescript file src/index.ts because otherwise, I can't reference "foo" inside of "foo" itself:

// foo/src/index.ts
import { something } from 'foo';

This error is thrown:
[vite:resolve] Failed to resolve entry for package "foo". The package may have incorrect main/module/exports specified in its package.json.

The above import only works, If "main" points to src/index.ts. Otherwise I would have to use relative paths to the imported file of the same project, for example

// foo/src/index.ts
import { something } from './someotherfile.ts';
Kristof Komlossy
  • 623
  • 2
  • 7
  • 19
  • I was looking into the same issue at: https://stackoverflow.com/questions/71014656/pnpm-workspace-dependency-and-also-supporting-publishing no response so far. Did you find a way to change it between development and publishing? – Jdruwe Feb 14 '22 at 08:30

1 Answers1

0

I found out, that vite needs the plugin vite-tsconfig-paths to find my main tsconfig.json to properly resolve the project:

// vite.config.ts
import tsconfigPaths from "vite-tsconfig-paths";

plugins: [
  tsconfigPaths({
    root: "../../",
  }),
],
Kristof Komlossy
  • 623
  • 2
  • 7
  • 19