SASS vs CSS Modules vs CSS-in-JS vs Compile time CSS-in-JS. Who wins?

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • Appwrite - The Open Source Firebase alternative introduces iOS support
  • SonarLint - Deliver Cleaner and Safer Code - Right in Your IDE of Choice!
  • Scout APM - Less time debugging, more time building
  • vite

    Next generation frontend tooling. It's fast!

    And second problem, because all of our styles is just abstract global CSS we don't have a TypeScript support to check that our style really exist. And the resulting problem we don't have good IDE intelligence (especially if we have have additionalData that import of some files that contain SASS vars and mixins, in Webpack/Vite config). Yeah, we have solutions like:

  • typescript-plugin-css-modules

    A TypeScript language service plugin providing support for CSS Modules.

    But for VSCode we need setup TypeScript LS to use workspace version. For more information go here or here.

  • Appwrite

    Appwrite - The Open Source Firebase alternative introduces iOS support . Appwrite is an open source backend server that helps you build native iOS applications much faster with realtime APIs for authentication, databases, files storage, cloud functions and much more!

  • vite-plugin-sass-dts

    This is a plugin that automatically creates a type file when using the CSS module type-safely.

    Vite plugin sass dts that will generate TypeScript declarations for our CSS Modules.

  • css-modules-typescript-loader

    Webpack loader to create TypeScript declarations for CSS Modules

    Or for Webpack CSS Modules TypeScript loader

  • uap-core

    The regex file necessary to build language ports of Browserscope's user agent parser.

    import { css } from 'styled-components' // Works only on the client-side // For SSR we need have some Context to Provide User-Agent from request context to React application context const USER_AGENT = window.navigator.userAgent; // More details about browser detect regex // here - https://github.com/ua-parser/uap-core/blob/master/regexes.yaml export const checkIsIE10OrOlder = /MSIE /g.test(USER_AGENT); export const checkIsIE11 = /Trident\//g.test(USER_AGENT); export const checkIsEdge = /Edge\//g.test(USER_AGENT); export const checkIsFireFox = /Firefox\//gi.test(USER_AGENT); export const checkIsChrome = /Chrome\//gi.test(USER_AGENT); export const checkIsSafari = /Safari\//gi.test(USER_AGENT); export const checkIsYandex = /YaBrowser\//gi.test(USER_AGENT); export const styleIE11Browser = (...args) => checkIsIE11 ? css(...args) : null; export const styleEdgeBrowser = (...args) => checkIsEdge ? css(...args) : null; export const styleMicrosoftBrowsers = (...args) => checkIsIE11 || checkIsEdge || checkIsIE10OrOlder ? css(...args) : null; export const styleIsNotMicrosoftBrowsers = (...args) => !checkIsIE11 && !checkIsIE10OrOlder ? css(...args) : null; export const styleFireFoxBrowser = (...args) => checkIsFireFox ? css(...args) : null; export const styleSafariBrowser = (...args) => checkIsSafari ? css(...args) : null; export const styleYandexBrowser = (...args) => checkIsYandex ? css(...args) : null; export const browser = { ie: styleMicrosoftBrowsers, ie11: styleIE11Browser, edge: styleEdgeBrowser, notIE: styleIsNotMicrosoftBrowsers, firefox: styleFireFoxBrowser, moz: styleFireFoxBrowser, safari: styleSafariBrowser, yandex: styleYandexBrowser, };

  • linaria

    Zero-runtime CSS in JS library

    Linaria (Most popular, support React and Svelte)

  • vanilla-extract

    Zero-runtime Stylesheets-in-TypeScript

    Vanilla extract (very interesting, support more bundlers than Linaria)

  • SonarLint

    Deliver Cleaner and Safer Code - Right in Your IDE of Choice!. SonarLint is a free and open source IDE extension that identifies and catches bugs and vulnerabilities as you code, directly in the IDE. Install from your favorite IDE marketplace today.

  • compiled

    A familiar and performant compile time CSS-in-JS library for React.

    Compiled (Compile time CSS-in-JS solution from Atlassian)

  • razzle

    ✨ Create server-rendered universal JavaScript applications with no configuration

    Somehow at the interview I was asked "what i think about difficulty of configuring Webpack for Linaria, at that moment I realized, what to find a solution to set up Linaria with SSR is not simple task", but I will show you the final result for example Razzle config:

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts