egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
9.29k stars 223 forks source link

Import tsup config from package #1196

Closed Grsz closed 2 months ago

Grsz commented 2 months ago

Hi!

I have a monorepo, and I want to store my reusable tsup configs in a separate package to avoid having to duplicate configs. I want to do so without having to build the package every time (use tsup to compile tsup configs is quite an overkill, that's how I did it before).

The only thing I changed compared to my previous build first approach is the "main" field, it was "main": "./dist/index.js".

Now the package.json in @repo/tsup-config package contains fields:

"name": "@repo/tsup-config",
  "version": "0.0.0",
  "private": true,
  "sideEffects": false,
  "main": "./src/index.ts",

When I import it inside anothe package in a tsup.config.ts as:

import { defineConfig, type Options } from 'tsup';
import { base } from '@repo/tsup-config';

export default defineConfig((options: Options) => ({
  ...base,
  ...options,
}));

However, it throws: Unknown file extension ".ts".

Interestingly, if I move the exact same fie (that exports base, containing the reusable tsup config) to src, and import it as import { base } from '@/base'; (using absolute path here too, I was thinking maybe that's the issue), it works fine.

Any suggestions?

Upvote & Fund

Fund with Polar

sxzz commented 2 months ago

tsup won't transpile TS files from external packages, similar to Vite. Use importx to import TS files.