Skip to content

css.inject adds import './style.css'; to CJS builds #1135

Description

@Harris-Miller

Reproduction link or steps

Create a repo with a src/index.ts and a src/styles.css. src./index.ts needs to have import './styles.css'; Populate styles.css with whatever css you want

Have @tsdown/css as a dependency

tsdown.config.ts should be configured with at least:

{
  css: { inject: true },
  entry: ['src/index.ts'],
  fixedExtension: true,
  format: ['esm', 'cjs'],
}

After running tsdown, the very first line of both dist/index.mjs and dist/index.cjs has import './style.css';, dist/indest.cjs should have require('./style.css');

What is expected?

dist/indest.cjs should have require('./style.css');

What is actually happening?

dist/indest.cjs has an ESM import import './style.css';

Any additional comments?

Current workaround, replace css: { inject: true } } with the following in tsdown.config.ts:

banner: ({ format }) => ({ js: format === 'cjs' ? "require('./style.css');" : "import './style.css';" }),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions