Repository navigation
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
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-elementsalso 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
npx create-stencil@latest(npm init stencil@latest still errors for me)- add
globalStyle: 'src/global/styles.css',tostencil.config.ts. - create
./src/global/styles.cssfile with some css in it. - remove
distandwwwfrom output targets and leave onlydist-custom-elements - run
npm run build
Code Reproduction URL
Additional Information
Related to discussion in #6584
Activity
ESkeltonUniverus commentedon Mar 10, 2026
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
distoutput target intodist-custom-elementsoutput target. Its not really a big deal, but would be nice to get rid of itjohnjenkins commentedon Mar 10, 2026
mainly 'cos of the preferred solution:
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 😅
iterox commentedon Oct 13, 2026
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-loadingdistlayout (dist/<namespace>/<namespace>.css).The internal
dist-global-stylesoutput target already does exactly this, but it can't be configured by users:VALID_CONFIG_OUTPUT_TARGETS, so{ type: "dist-global-styles", file }fails with "Invalid outputTarget type", andvalidateOutputTargetsonly keeps targets that one of its validators returns, so the target is silently dropped.For now we work around this with a
pnpm patchon@stencil/core4.45.2. The patch addsDIST_GLOBAL_STYLEStoVALID_CONFIG_OUTPUT_TARGETSand adds a small validator that resolvesfileto an absolute path. It works, but we have to re-apply it on every Stencil upgrade.We see that the
v5branch solves this with theglobal-styleoutput target (input,fileName,dir). Two questions:dist-global-stylesuser-configurable?5.0.0-beta.22), so we can plan our migration toglobal-style?