Skip to content

bug: dist-custom-elements do not output global styles #6630

Description

@dogoku

Prerequisites

Stencil Version

Any

Current Behavior

Currently only dist and www output global styles, which works as described in the docs.

However, if someone wants to use dist-custom-elements and global styles, they have to use dist or www along with it.

It would be nice if we could either:

  • decouple global styles generation from specific output targets (breaking change, but more preferable)
  • make dist-custom-elements also output global styles (non-breaking, but duplicates css files)

The first option makes more sense, since globalStyles is its own property in the stencil config (same for globalScript). If someone specifies it, it is implied they want it generated, so it shouldn't matter what output targets they are using. And u could even control the output path.

But I would also be ok with the 2nd option, if its easier to implement. Only problem with that is if someone is using 2 or all 3 of the output targets (dist, dist-custom-elements, www), the same css is output in multiple locations for no reason.

Expected Behavior

dist-custom-elements should also output global styles.
Alternatively: When globalStyles is specified in stencil config, styles should be output regardless of output target.

System Info

Steps to Reproduce

  1. npx create-stencil@latest (npm init stencil@latest still errors for me)
  2. add globalStyle: 'src/global/styles.css', to stencil.config.ts.
  3. create ./src/global/styles.css file with some css in it.
  4. remove dist and www from output targets and leave only dist-custom-elements
  5. run npm run build

Code Reproduction URL

https://github.com/dogoku/stencil-global-styles

Additional Information

Related to discussion in #6584

Activity

  1. added
    Feature: Want this? Upvote it!
    and removed on Mar 6, 2026
  2. added
    Stencil v5
    and removed
    Feature: Want this? Upvote it!
    on Mar 6, 2026
  3. ESkeltonUniverus commented on Mar 10, 2026

    @ESkeltonUniverus

    isn't this just a bug? Why would this be tagged with V5?

    Because of this issue, I have a post build script that injects the global css from the dist output target into dist-custom-elements output target. Its not really a big deal, but would be nice to get rid of it

  4. johnjenkins commented on Mar 10, 2026

    @johnjenkins
    Contributor

    mainly 'cos of the preferred solution:

    decouple global styles generation from specific output targets (breaking change, but more preferable)

    that's a feature that needs some thought.

    Additionally, I'm trying not to context switch too much - just concentrating on v5 dev now as much as I can.
    I figure it's always been like this so can be like this for a bit longer 😅

  5. iterox commented on Oct 13, 2026

    @iterox

    We ran into the same limitation while merging our two packages (dso-toolkit, which used to compile its global stylesheet with gulp, and @dso-toolkit/core, our Stencil library) into one Stencil-built package.

    Our use case: we ship a single global stylesheet (globalStyle: "src/dso.scss") that consumers load on its own, at a stable, project-defined path (dist/dso.css), independent of the lazy-loading dist layout (dist/<namespace>/<namespace>.css).

    The internal dist-global-styles output target already does exactly this, but it can't be configured by users:

    • it is missing from VALID_CONFIG_OUTPUT_TARGETS, so { type: "dist-global-styles", file } fails with "Invalid outputTarget type", and
    • even with it added there, validateOutputTargets only keeps targets that one of its validators returns, so the target is silently dropped.

    For now we work around this with a pnpm patch on @stencil/core 4.45.2. The patch adds DIST_GLOBAL_STYLES to VALID_CONFIG_OUTPUT_TARGETS and adds a small validator that resolves file to an absolute path. It works, but we have to re-apply it on every Stencil upgrade.

    We see that the v5 branch solves this with the global-style output target (input, fileName, dir). Two questions:

    1. Would you consider a minimal, purely additive change in v4 that makes dist-global-styles user-configurable?
    2. If not, is there a rough timeline for a stable v5 (currently 5.0.0-beta.22), so we can plan our migration to global-style?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stencil v5

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions