CSS modules for Embroider projects
embroider-css-modules
provides a set of tools and conventions to help you implement CSS modules. It is compatible with "bleeding-edge" Ember:
- Embroider on the strictest settings (including route splitting)
- TypeScript + Glint
<template>
tag
ember install embroider-css-modules
Use Glint or <template>
tag? ✨
-
Update your template registry to extend this addon's. Check the Glint documentation for more information.
import '@glint/environment-ember-loose'; import type EmbroiderCssModulesRegistry from 'embroider-css-modules/template-registry'; declare module '@glint/environment-ember-loose/registry' { export default interface Registry extends EmbroiderCssModulesRegistry, /* other addon registries */ { // local entries } }
-
In a
<template>
tag, use the named import to consume the{{local}}
helper./* app/components/hello.css */ .message { align-items: center; display: flex; height: 100%; justify-content: center; } .emphasize { font-size: 64px; font-style: italic; }
/* app/components/hello.gts */ import { local } from 'embroider-css-modules'; import styles from './hello.css'; <template> <div class={{local styles "message" "emphasize"}}> Hello world! </div> </template>
The addon provides 1 helper:
{{local}}
Throughout the section, you can assume that there is a styles
object, which maps local class names to global ones.
// An example
const styles = {
'container': 'lzeQ4',
'is-inline': 'mJGCE',
'is-wide': '_2lPSR',
'no-feedback': 'YpQbt',
};
The {{local}}
helper is useful when you want to apply multiple styles.
Before: With the {{concat}}
helper
After: With the {{local}}
helper
To conditionally apply multiple styles, use the {{array}}
helper.
Example
The {{local}}
helper uses positional arguments so that styles are applied in sequence. Pass the styles
object first, then the local class name(s).
The {{local}}
helper returns a concatenated string. The string lists the global class names in the same order as the local ones.
- Ember.js v4.12 or above
- Node.js v20 or above
See the Contributing guide for details.
This project is licensed under the MIT License.