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

@collagejs/vite-css

v0.1.0

Published

Vite plug-in for automatic CSS injection in CollageJS micro-frontends

Downloads

98

Readme

 @collagejs/vite-css

This Vite plug-in can be used to generate a function compliant with the CollageJS CorePiece.mount specification. This function knows, by virtue of its own nature, which CSS bundles are needed by any CollageJS pieces, and can therefore ensure they mount and dismount in synchrony with the piece or pieces.

Quickstart

  1. Install the plug-in:
    npm i -D @collagejs/vite-css
  2. Add it to the list of Vite plug-ins in vite.config.ts:
    import { collageJsCssPlugin } from "@collagejs/vite-css";
    
    export default defineConfig({
        plugins: [
            ...,
            collageJsCssPlugin({ serverPort: 4111 /*, etc. */ })
        ],
        ...
    });
  3. On each input file, which by default is only the one named src/piece.ts, we import the function factory and use it in all factory functions that create CollageJS pieces:
    import { buildPiece } from "@collagejs/<insert your framework here>";
    import { cssMountFactory } from "@collagejs/vite-css/ex";
    ...
    
    // IMPORTANT:  The first argument to the function is the file's name.
    // Assuming this is src/piece.ts, we pass "piece" (no extension).
    const cssMount = cssMountFactory('piece' /*, { options } */);
    
    export function myPieceFactory() {
        const piece = buildPiece(...);
        return {
            mount: [cssMount, piece.mount],
            update: piece.update
        };
    }

Note how we build cssMount outside the factory function. This is because we can reuse it in all factory functions exported by the module. We only need one of these per module (not per factory function).

This should work for any Vite-powered project.

⚠️ IMPORTANT: The CSS-mounting function features FOUC prevention, but it only works if it is listed first in the array of mount functions, like shown in the example.

Plug-in Options

serverPort

The only required option: The port number this project will be assigned when running locally using npm run dev or npm run preview.

localhostSsl

A Boolean value, whose default value is false that indicates if Vite's development server should use SSL (https).

entryPoints

This is one very important option to know. Its default value is src/piece.ts, but can also be an array of strings. In short, this is the list of files that export CollageJS piece factories. This is the list of modules whose exports we want visible.

projectId

This should be set to a unique identifier of maximum 20 characters that uniquely identifies the CollageJS pieces provided by the Vite project. It is used to uniquely name CSS bundles, so the automatic CSS-mounting algorithm can identify them properly.

If no value is provided, the package.json's name property will be used by default (or at least the first 20 characters of it).

⚠️ Be sure to provide a project ID or a name to your project in package.json.

assetFileNames

This option accepts a Rollup-compliant pattern for asset filenames. Refer to its documentation online for full details. Note, however, that the pattern will only be respected for non-CSS assets. CSS files will be named in the form cjcss(<project id>)<pattern>, so not exactly the provided pattern.

By default, this option's value is 'assets/[name]-[hash][extname]'. Yes, you may add sub directories to the pattern.

Factory Function Options

logger

Used to control where or when log entries go. When set to true or not set, logging occurs through the browser's standard console. When set to false, logging is turned off; when set to a custom logger object, then the logger object is used for logging, and the object decides what happens with those log entries.

loadTimeout

The CSS-mounting algorithm provided by this package features FOUC (Flash Of Unstyled Content) prevention by ensuring the browser loads the CSS before giving way to the micro-frontend/piece mounting process. This property, whose default value is 1500, is used to set the amount of time (in milliseconds) the FOUC-prevention feature waits for CSS to load before giving up.

failOnTimeout and failOnError

These properties, when set to true, tell the FOUC-prevention algorithm to throw an error whenever a CSS resource fails to load, or takes too long to load. Their default value is false, which signals the algorithm to emit console warnings only.

When throwing errors, the micro-frontend/piece mounting process interrupts.