Giter Site home page Giter Site logo

Comments (10)

metonym avatar metonym commented on May 17, 2024 8

@uribalb we are working on a custom Carbon class/element extractor for purgecss

from carbon-components-svelte.

metonym avatar metonym commented on May 17, 2024 7

I'm glad you brought this up. Documentation on real (production) set-ups is forthcoming.

The example in the README is a "quick start" method.

For now, please refer to this boilerplate for a full SASS webpack set-up. Note that the SASS import is still not optimized per component.

from carbon-components-svelte.

metonym avatar metonym commented on May 17, 2024 6

@uribalb SCSS is currently the best method for optimizing CSS performance (i.e. minimizing the CSS size). Check out the Carbon guide on optimizing Sass builds.

Essentially, SCSS allows your to import the styles for individual components.

Dependencies:

  • node-sass
  • carbon-components (version 10.21 or greater)
  • @carbon/themes (if using any theme besides the default white theme)

The equivalent SCSS for all.css:

  $feature-flags: (
    enable-css-custom-properties: true,
    grid-columns-16: true
  );

  @import "@carbon/themes/scss/themes";

  :root {
    @include carbon--theme($carbon--theme--white, true);
  }

  :root[theme="g10"] {
    @include carbon--theme($carbon--theme--g10, true);
  }

  :root[theme="g90"] {
    @include carbon--theme($carbon--theme--g90, true);
  }

  :root[theme="g100"] {
    @include carbon--theme($carbon--theme--g100, true);
  }

  $css--font-face: true;
  $css--helpers: true;
  $css--body: true;
  $css--use-layer: true;
  $css--reset: true;
  $css--default-type: true;
  $css--plex: true;

  @import "carbon-components/scss/globals/scss/_css--reset.scss";
  @import "carbon-components/scss/globals/scss/_css--font-face.scss";
  @import "carbon-components/scss/globals/scss/_css--helpers.scss";
  @import "carbon-components/scss/globals/scss/_css--body.scss";
  @import "carbon-components/scss/globals/grid/_grid.scss";

  /* import individual components SCSS */
  @import "carbon-components/scss/components/button/button";

from carbon-components-svelte.

Taha-Firoz avatar Taha-Firoz commented on May 17, 2024 3

@metonym So from what I think you mean, I made a style.scss file in my src folder, pasted all of this stuff you've written and imported that into my App.svelte how large should my exported css be. Because theres still alot of css being generated for a single button. Can you make a "For Dummies" style guide, I'm very new to all of this css stuff and I'm having a hard time following along.

from carbon-components-svelte.

NickStarlight avatar NickStarlight commented on May 17, 2024 2

I'm currently doing this:

<script>
  import { Button } from 'carbon-components-svelte';
</script>

<main>
	<Button>Primary</Button>
</main>

<style lang="scss" global>
  @import 'carbon-components/scss/components/button/button';
</style>

Sadly, this bundles the button CSS globally with the 'global' attribute, without it, Svelte will remove the import in build time because it doesn't know it's being used(See sveltejs/svelte-preprocess#44).

You need postcss installed.

from carbon-components-svelte.

uribalb avatar uribalb commented on May 17, 2024 2

@metonym Thanks. I think your comment should be in the docs and readme, as the official method for css optimization (for now) since svelte people tend to care a lot about these things

from carbon-components-svelte.

uribalb avatar uribalb commented on May 17, 2024

I've been trying to do the same with rollup and purgecss but it removes all of carbon's css

from carbon-components-svelte.

uribalb avatar uribalb commented on May 17, 2024

@uribalb we are working on a custom Carbon class/element extractor for purgecss

OK. Little precision: I'm using the routify 2.x template (npx @roxi/routify init --branch 2.x). It uses postcss and rollup to build the project. I do:

<style  global>
  @import "carbon-components-svelte/css/all.css";
</style>

in App.svelte
Would you recommend to keep using carbon normally and change the config files when the plugin is ready or is there something that I should start doing with my code to make future config easier ?

from carbon-components-svelte.

ion1 avatar ion1 commented on May 17, 2024

Would it be feasible for the components to import their own CSS directly, so you would only need have things such as the theme and the reset CSS in the global style?

from carbon-components-svelte.

metonym avatar metonym commented on May 17, 2024

@ion1 I've previously explored generating CSS for individual components from the source SCSS. However, even by taking out the reset styles, there is still a lot of duplicate CSS because many components import the same SCSS mixins/helpers.

Therefore, you'll still need an extra, build-step that removes unused selectors.

Currently, the best approach (recommended by the core Carbon team) is to use SCSS and import individual component styles.

from carbon-components-svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.