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

fable-css-modules

v1.8.0

Published

Generate Fable bindings for your CSS modules classes

Downloads

55

Readme

fable-css-modules

Generate Fable bindings for your CSS modules classes

Allowing you to leverage CSS modules in your Fable projects, in a safe way.

module Components.QRCode

open Fable.Core.JsInterop
open Feliz

// Import the CSS module
let private classes : CssModules.Components.QRCode = import "default" "./QRCode.module.scss"

[<ReactComponent>]
let QRCode () =
    Html.div [
        prop.className classes.qrCode // Here you get completion of the defined CSS classes
        prop.children [
            // ..
        ]
    ]

Prelude

fable-css-module can be used with any bundler (Vite, Webpack, etc.) that supports CSS modules and any framework (React, Vue, etc.).

This tools supports:

  • CSS modules identified by *.module.scss
  • SASS/SCSS modules identified by *.module.sass or *.module.scss

Installation

fable-css-modules is an NPM tool and can be installed using a Node.js package manager.

Example:

npm install fable-css-modules

Usage

The tool can be call using npx fable-css-modules or npx fcm.

fcm

Generate bindings for all the CSS modules in <source> folder to <outFile> file

Positionals:
  source  Folder where the CSS modules are located       [string] [default: "."]

Options:
      --version   Show version number                                  [boolean]
      --outFile   Output file where the binding will be written
                                             [string] [default: "CssModules.fs"]
      --internal  Mark the generated module as internal[boolean] [default: true]
  -h, --help      Show help                                            [boolean]

Example:

src
└─── Components
    │    QRCode.fs
    │    QRCode.module.scss
    └─── User
            History.fs
            History.module.scss

If you invoke npx fcm in the src folder, a file CssModules.fs will be generated in src with the following content:

//-----------------------------------------------------------------------------
//        This code was generated by fable-css-modules.
//        Changes to this file will be lost when the code is regenerated.
//-----------------------------------------------------------------------------

[<RequireQualifiedAccess>]
module internal CssModules

open Fable.Core

module Components =

    type QRCode =

        /// <summary>
        /// Binding for <c>qr-code</c> class
        /// </summary>
        [<Emit("$0[\"qr-code\"]")>]
        abstract qrCode : string

    module User =

        type History =

            /// <summary>
            /// Binding for <c>history-container</c> class
            /// </summary>
            [<Emit("$0[\"history-container\"]")>]
            abstract history-container : string

You should now add <Compile Include="CssModules.fs" /> to your fsproj file.

You can now use the CssModules module in your Fable code.

src/Components/QRCode.fs

module Components.QRCode

open Fable.Core.JsInterop
open Feliz

let private classes : CssModules.Components.QRCode = import "default" "./QRCode.module.scss"

[<ReactComponent>]
let QRCode () =
    Html.div [
        prop.className classes.qrCode
        prop.children [
            // ..
        ]
    ]

Best practices

You should avoid committing the generated files to your repository. This will force you to run fable-css-modules every time you want to build your project.

This help make sure that your CSS modules bindings is up to date with the actual CSS modules.

Watch mode

Watch mode is not yet supported out of this box by fable-css-modules.

But you can easily add using nodemon.

npx nodemon -e module.scss --exec "fcm"

This command will automatically run fcm every time a change to a .module.scss file is detected.

IDE tips

It can happen that IDEs takes a moment to reflect the changes in the generated file.

Here are a few tips to help force them to update their references.

Ionide

Navigating to the CssModules.fs file seems to make it refresh the file.

You can navigate to it by Ctrl+Click on the reference.

If this is not enough, you can try to add a space to the file and saving it manually.

Remember, CssModules.fs should not be commited so adding non meaningful spaces don't really matter

Rider

You can click to File > Reload All from Disk or press Ctrl+Alt+Y