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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@demching113/css-modules-loader-core

v2.0.1

Published

A loader-agnostic CSS Modules implementation, based on [email protected]

Downloads

105

Readme

CSS Module Loader Core

A loader-agnostic CSS Modules implementation, based on PostCSS@8

If you don't use plugins for PostCSS@8, use the original package instead.

Build Status

Notice

This is a modified repository of css-modules-loader-core with the following changes:

  1. Rewrite in Typescript.
  2. Update some dependencies to latest version: PostCSS and related plugins.
  3. Change the usage of file-system-loader.

The original package depends on PostCSS@6 which has a different usage of plugins to the latest PostCSS@8. Incompatible plugins is the main reason I created this package. You may install the original package if you are not using custom plugins.

Usage of this package should be the same as original repo unless you are using file-system-loader. Check here for details.

API

import Core from '@demching113/css-modules-loader-core'
let core = new Core()

core.load

core.load( sourceString , sourcePath, depTrace , pathFetcher ) => Promise({ injectableSource, exportTokens })

Processes the input CSS sourceString, looking for dependencies such as @import or :import. Any localisation will happen by prefixing a sanitised version of sourcePath When dependencies are found, it will ask the pathFetcher for each dependency, resolve & inline any imports, and return the following object:

  • injectableSource: the final, merged CSS file without @import or :import statements
  • exportTokens: the mapping from local name to scoped name, as described in the file's :export block

These should map nicely to what your build-tool-specific loader needs to do its job.

new Core([plugins])

The default set of plugins is [postcss-modules-local-by-default, postcss-modules-extract-imports, postcss-modules-scope] (i.e. the CSS Modules specification). This can override which PostCSS plugins you wish to execute, e.g.

import Core from '@demching113/css-modules-loader-core'
import autoprefixer from 'autoprefixer'
import colorFunctions from 'postcss-color-function'

// Don't run local-by-default, but use colorFunctions
// beforehand and autoprefixer afterwards:
let core = new Core([
  colorFunctions,
  Core.extractImports,
  Core.scope,
  autoprefixer("Last 2 Versions")
])

File System Loader

This loader was used only for testing in original repository. However, it doesn't work because the file path is not resolved correctly. See related issue.

So I try to fix the bug and end up changing its usage.

P.S. This is tested on Windows only so it may not work on Unix system.

import { FileSystemLoader } from '@demching113/css-modules-loader-core';
// Specify the absolute path of root. E.g. C:\users\your\root\of\src
let fileLoader = new FileSystemLoader(rootAbsolutePath);

// or with using plugins
let fileLoader = new FileSystemLoader(rootAbsolutePath, [
  // your plugins
]);

fileLoader.load

fileLoader.load( sourceString , sourceRelativePath , depTrace ) => Promise({ injectableSource, exportTokens })

The usage is similar to core.load except you don't need to provide pathFetcher.

Also, you may need to provide the file path sourceRelativePath relative to rootAbsolutePath.

For example, the rootAbsolutePath is /root/of/src and you want to load /root/of/src/styles/main.css:

let fileLoader = new FileSystemLoader(`/root/of/src`);
fileLoader.load(
  contents, // contents of main.css
  `styles/main.css`, // relative path
)