
Security News
AI Agent Lands PRs in Major OSS Projects, Targets Maintainers via Cold Outreach
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.
single-spa-css
Advanced tools
Lifecycle helpers for loading and unmounting css.
npm install single-spa-css
pnpm install single-spa-css
yarn add single-spa-css
import singleSpaCss from 'single-spa-css';
const cssLifecycles = singleSpaCss({
// required: a list of CSS URLs to load
// can be omitted if webpackExtractedCss is set to true, do not specify webpack extracted css files here
cssUrls: ['https://example.com/main.css'],
// optional: defaults to false. This controls whether extracted CSS files from webpack
// will automatically be loaded. This requires using the ExposeRuntimeCssAssetsPlugin,
// which is documented below.
webpackExtractedCss: false,
// optional: defaults to true. Indicates whether the <link> element for the CSS will be
// unmounted when the single-spa microfrontend is unmounted.
shouldUnmount: true,
// optional: defaults to 5000. The number of milliseconds to wait on the <link> to load
// before failing the mount lifecycle.
timeout: 5000
})
const reactLifecycles = singleSpaReact({...})
// Export an array of lifecycles to integrate with a framework's
// single-spa lifecycles. The order matters.
export const bootstrap = [
cssLifecycles.bootstrap,
reactLifecycles.bootstrap
]
export const mount = [
// The css lifecycles should be before your framework's mount lifecycle,
// to avoid a Flicker of Unstyled Content (FOUC)
cssLifecycles.mount,
reactLifecycles.mount
]
export const unmount = [
// The css lifecycles should be after your framework's unmount lifecycle,
// to avoid a Flicker of Unstyled Content (FOUC)
reactLifecycles.unmount,
cssLifecycles.unmount
]
If you want some css files to unmount, but others to stay mounted, use the following syntax:
const cssLifecycles = singleSpaCss({
cssUrls: [
{
href: "https://example.com/main.css",
shouldUnmount: true,
},
{
href: "https://example.com/other.css",
shouldUnmount: false,
},
],
});
single-spa-css exposes a webpack plugin that integrates with mini-css-extract-plugin to allow you to load CSS files that are extracted and otherwise would not be loaded. The webpack plugin exposes the names of the extracted CSS files to your bundle under the __webpack_require__.cssAssets and __webpack_require__.cssAssetFileName variables. The cssAssets variable contains the name of the webpack chunk, and the cssAssetFileName function converts the chunk name into the extracted CSS asset's file name. These can be used manually, or you can specify the webpackExtractedCss option in single-spa-css to have it automatically mount and unmount those CSS files.
In your webpack config, add the following:
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ExposeRuntimeCssAssetsPlugin = require("single-spa-css/ExposeRuntimeCssAssetsPlugin.cjs");
module.exports = {
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new ExposeRuntimeCssAssetsPlugin({
// The filename here must match the filename for the MiniCssExtractPlugin
filename: "[name].css",
}),
],
};
FAQs
Lifecycle helpers for loading CSS
The npm package single-spa-css receives a total of 8,083 weekly downloads. As such, single-spa-css popularity was classified as popular.
We found that single-spa-css demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.