npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

scoped-rem-loader

v0.2.1

Published

Webpack loader of scoped-rem, a tool that makes CSS rem units relative to a custom root font size.

Downloads

18

Readme

scoped-rem-loader

GitHub Repo npm version npm download npm license

Webpack loader of scoped-rem, a tool that makes CSS rem units relative to a custom root font size.

Why needed

In short, mixing rem units from different sources may lead to inconsistent scaling behavior.

When using rem units in CSS, they are always relative to the root element (<html>), which can lead to inflexibility in certain scenarios, such as when you want different scaling factors in different sections of a webpage or application.

Here is the scenario from author's experience:

  • Here are two mobile applications called A and B, both using a WebView to render web content. And they are managed by different teams. Each team has its own design system and style guidelines.
  • Specifically, application B uses a base font size of 13.3333vw and application A uses a different base font size of 26.6667vw.
  • One day, the team managing application B decided to integrate some components from application A into their app. However, although both applications use rem units for styling, the components from application A did not scale correctly within application B because the rem units in application A were based on a different root font size than those in application B.
  • Dev from application B are frustrated because they have to manually modify all related values in the CSS files of application A to make them work correctly within application B, which is time-consuming and error-prone. And if application A updates their components, the modifications need to be redone.
  • To maximize code reuse among applications, reduce development time and maintenance costs, the team needed a way to make the rem units in the imported components from application A keep their original scaling behavior as if they still conformed to application A's root font size, even when rendered within application B, without any modification to the original CSS files.

That is why scoped-rem was created.

Installation

npm install --save-dev scoped-rem-loader
# pnpm
pnpm add -D scoped-rem-loader
# yarn
yarn add -D scoped-rem-loader

Usage

Just add scoped-rem-loader to your webpack config:

Remember that scoped-rem-loader can only handle CSS files, so it should be placed before (logically) css-loader or other loaders that transform CSS to non-CSS files.

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader',
          'scoped-rem-loader'
        ]
      }
    ]
  }
};

Then edit the import statement of your CSS file with query parameters to configure the behavior of scoped-rem-loader:

Parameter descriptions can be found here.

// from 
// import './styles.css';

// to
import './styles.css?rem-scoped&varname=a-root-font-size&rootval=26.6667vw';

Then styles will be transformed from:

.foo {
  width: 2rem;
  height: 3rem;
}

to

:root {
  --a-root-font-size: 26.6667vw;
}

.foo {
  width: calc(2 * var(--a-root-font-size));
  height: calc(3 * var(--a-root-font-size));
}

Or you can just transform rem to calc() without declaring the CSS variable by omitting the rootval parameter:

import './styles.css?rem-scoped&varname=a-root-font-size';

Then styles will be transformed from:

.foo {
  width: 2rem;
  height: 3rem;
}

to

.foo {
  width: calc(2 * var(--a-root-font-size));
  height: calc(3 * var(--a-root-font-size));
}