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
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • 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.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • 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)

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • 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