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

vite lib mode/vite-dts build errors #14

Closed
zwgnr opened this issue Dec 15, 2022 · 1 comment
Closed

vite lib mode/vite-dts build errors #14

zwgnr opened this issue Dec 15, 2022 · 1 comment

Comments

@zwgnr
Copy link

zwgnr commented Dec 15, 2022

I am currently in the processes of porting over a design system from Vanilla Extract to Macaron.

I was compiling with Vite in Lib mode using vite-dts in Vanilla Extract and everything was working fine. When using Macaron, the builds are failing.

viteissue

Here's the vite.config

import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { peerDependencies } from './package.json';
import { macaronVitePlugin } from '@macaron-css/vite';

const externals = [...Object.keys(peerDependencies)];

export default defineConfig({
  build: {
    lib: {
      entry: 'src/index.ts',
      fileName: 'index',
      formats: ['cjs', 'es'],
    },
    rollupOptions: {
      external: externals,
    },
  },
  plugins: [
    macaronVitePlugin(),
    dts({
      beforeWriteFile: (filePath, content) => ({
        content,
        filePath: filePath.replace('src', ''),
      }),
      compilerOptions: {
        baseUrl: './src/',
        emitDeclarationOnly: true,
        noEmit: false,
      },
      exclude: ['src/**/*.stories.tsx'],
      outputDir: 'dist/types',
    }),
  ],
});

FWIW, I was able to get builds working by removing vite-dts from the vite.config, building, and then running a separate build step with tsc and the following flags "tsc --emitDeclarationOnly --declaration --declarationDir dist/types".

@Mokshit06
Copy link
Member

I believe this is something that's occurring because extracted_*.css files don't actually exist in the file system. They are virtual and are created and resolved by macaron's bundler plugins, but typescript is unable to resolve them.
This isn't something that can be fixed since we can't make ts resolve the virtual files, so removing vite-dts and running tsc as a different process is probably the only way to make it work

@zwgnr zwgnr closed this as completed Dec 16, 2022
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