Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make css just be copied into dist #1287

Open
da1z opened this issue Feb 5, 2025 · 4 comments
Open

How to make css just be copied into dist #1287

da1z opened this issue Feb 5, 2025 · 4 comments

Comments

@da1z
Copy link

da1z commented Feb 5, 2025

I have config like this:

export default defineConfig({
  entry: ['src/**/*.(ts|tsx|css)'],
  format: ['esm'],
  dts: true,
  treeshake: true,
  clean: true,
  sourcemap: true,
  external: ['react', 'react-dom'],
});

i have couple css files in src i need to package with code in dist.
i get this error on tsup build

DTS Build start error TS6054: File 'mycssfile.css' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.

how can i tell dts to not process css files?

this seems to be not working anymore. rollup still process file https://github.com/egoist/tsup/blob/main/src/rollup.ts#L87

@Joseph2424
Copy link

Ran into the same issue. Did you find a solution?

@da1z
Copy link
Author

da1z commented Feb 19, 2025

@Joseph2424 i ended up with config like this:

import { globSync } from 'glob';
import path from 'path';
import { defineConfig } from 'tsup';
import { fileURLToPath } from 'url';

export default defineConfig({
  entry: ['src/**/*.(ts|tsx|css)'],
  format: ['esm'],
  dts: {
    entry: Object.fromEntries(
      globSync('src/**/*.{ts,tsx}').map((file) => [
        path.relative(
          'src',
          file.slice(0, file.length - path.extname(file).length)
        ),
        fileURLToPath(new URL(file, import.meta.url)),
      ])
    ),
  },
  treeshake: true,
  splitting: false,
  clean: true,
  sourcemap: true,
  external: ['react', 'react-dom'],
  loader: {
    '.css': 'copy',
  },
});

@Joseph2424
Copy link

Joseph2424 commented Feb 19, 2025

Unfortunately, adding "css" as an entry fails for me. However, removing css as an entry allows tsup to compile. Otherwise, I get an error saying css is not supported.

ESM ⚡️ Build success in 877ms
error TS6054: File '/Users/rosadojoseph/Github/pickster/src/web/pickster/packages/plugins/design/src/lib/styles/globals.css' has an unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.
The file is in the program because:
Root file specified for compilation

import { defineConfig } from 'tsup';

export default defineConfig((options) => ({
...options,
entry: ['src/**/!(.d|.stories|*.test).{ts,tsx}'],
format: ["esm"],
clean: true,
bundle: false,
dts: true,
sourcemap: true,
splitting: false,
treeshake: true,
external: ['react', 'reac-dom', 'class-variance-authority'],
minify: !options.watch,
loader: {
".css": "copy",
".module.css": "copy",
}
}));

@Joseph2424
Copy link

You are a life saver, I spent nearly a week trying to figure this out. Turns out the issue was with the DTS flag. I had it set to true initially. Instead I replaced it with your copy function and it worked.

Thank You!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants