Skip to content

Some styles missing when previewing or publishing project #107

@hobbes7878

Description

@hobbes7878

For anyone coming here, there appear to be some edge cases where a plugin we use to strip out unused style rules gets a bit greedy and can strip out some rules used in your custom svelte components. This likely only applies to styles applied through our utility class names, for example:

<p class="uppercase">lorem ipsum<p>

To get around this issue, you have a few different options:

  1. Use SCSS mixins instead of class names in the component whose styles are being stripped out.
<p>lorem ipsum</p>

<style lang="scss">
  @use '@reuters-graphics/graphics-components/dist/scss/mixins' as mixins;

  p {
    @include mixins.uppercase;
  }
</style>
  1. You can disable the plugin entirely by commenting out this line in vite.config.ts at the root of your project. Like this:
plugins: [
    sveltekit(),
    dsv(),
    svelteKitPagesPlugin(),
    // purgeCss(),
],
  1. Disabling the plugin will lead to slightly bloated stylesheets for your project. Alternatively, you can also use the plugin's safelisting config options to safe guard specific style rules individually. Like this:
plugins: [
    sveltekit(),
    dsv(),
    svelteKitPagesPlugin(),
    purgeCss({
      safelist: {
        standard: [ 'uppercase' ], // A specific class name
        greedy: [
          /^text-/, // Regular expressions can be used here to capture several classes
        ],
      },
    }),
],

📌 If you have this issue please add a comment here with a link to your project's repo. We're looking for more examples to help nail down why this sometimes happens...

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions